/*
 *  Copyright 2019-2020 Zheng Jie
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package com.fzhucc.modules.sciPersonnelInfo.service;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.fzhucc.config.FileProperties;
import com.fzhucc.exception.BadRequestException;
import com.fzhucc.modules.Msg.domain.Msg;
import com.fzhucc.modules.Msg.domain.dto.SmallMsgDto;
import com.fzhucc.modules.Msg.repository.MsgRepository;
import com.fzhucc.modules.Tr.domain.TechnologyReType;
import com.fzhucc.modules.Tr.repository.TechnologyReTypeRepository;
import com.fzhucc.modules.expert.domain.ExpertConsultationConfig;
import com.fzhucc.modules.expert.domain.ExpertOfflineConfig;
import com.fzhucc.modules.expert.domain.ExpertReservation;
import com.fzhucc.modules.expert.domain.dto.ExpertConfigLists2Dto;
import com.fzhucc.modules.expert.domain.dto.ExpertConfigListsDto;
import com.fzhucc.modules.expert.repository.ExpertConsultationConfigRepository;
import com.fzhucc.modules.expert.repository.ExpertOfflineConfigRepository;
import com.fzhucc.modules.expert.repository.ExpertReservationRepository;
import com.fzhucc.modules.fenRecordLog.service.FenRecordLogService;
import com.fzhucc.modules.hot.domain.Hot;
import com.fzhucc.modules.hot.domain.HotRecord;
import com.fzhucc.modules.hot.repository.HotRecordRepository;
import com.fzhucc.modules.hot.repository.HotRepository;
import com.fzhucc.modules.loveModelRecord.domain.LoveModelRecord;
import com.fzhucc.modules.loveModelRecord.repository.LoveModelRecordRepository;
import com.fzhucc.modules.modelDemand.domain.ModelDemandAuditLog;
import com.fzhucc.modules.modelDemand.repository.ModelDemandAuditLogRepository;
import com.fzhucc.modules.sciCxResult.domain.SciCxResult;
import com.fzhucc.modules.sciCxResult.domain.SciCxResultInfo;
import com.fzhucc.modules.sciCxResult.domain.dto.SciCxResultDto;
import com.fzhucc.modules.sciCxResult.repository.SciCxResultInfoRepository;
import com.fzhucc.modules.sciCxResult.repository.SciCxResultRepository;
import com.fzhucc.modules.sciCxResult.service.mapstruct.SciCxResultInfoMapper;
import com.fzhucc.modules.sciCxResult.service.mapstruct.SciCxResultMapper;
import com.fzhucc.modules.sciEnterprise.domain.SciEnterprise;
import com.fzhucc.modules.sciEnterprise.repository.SciEnterpriseRepository;
import com.fzhucc.modules.sciEnterprise.service.mapstruct.SciEnterpriseMapper;
import com.fzhucc.modules.sciPersonnelInfo.domain.*;
import com.fzhucc.modules.sciPersonnelInfo.domain.dto.*;
import com.fzhucc.modules.sciPersonnelInfo.repository.*;
import com.fzhucc.modules.sciStudio.domain.SciStudio;
import com.fzhucc.modules.sciStudio.domain.SciStudioImg;
import com.fzhucc.modules.sciStudio.domain.SciStudioInfo;
import com.fzhucc.modules.sciStudio.domain.dto.SciStudioDto;
import com.fzhucc.modules.sciStudio.domain.dto.SciStudioImgDto;
import com.fzhucc.modules.sciStudio.repository.SciStudioImgRepository;
import com.fzhucc.modules.sciStudio.repository.SciStudioInfoRepository;
import com.fzhucc.modules.sciStudio.repository.SciStudioRepository;
import com.fzhucc.modules.sciStudio.service.mapstruct.SciStudioImgMapper;
import com.fzhucc.modules.sciStudio.service.mapstruct.SciStudioInfoMapper;
import com.fzhucc.modules.sciStudio.service.mapstruct.SciStudioMapper;
import com.fzhucc.modules.sciTechnologyDemand.domain.SciTechnologyDemand;
import com.fzhucc.modules.sciTechnologyDemand.domain.SciTechnologyDemandInfo;
import com.fzhucc.modules.sciTechnologyDemand.domain.SciTechnologyDemandMate;
import com.fzhucc.modules.sciTechnologyDemand.domain.SciTechnologyDemandRecord;
import com.fzhucc.modules.sciTechnologyDemand.domain.dto.*;
import com.fzhucc.modules.sciTechnologyDemand.repository.SciTechnologyDemandInfoRepository;
import com.fzhucc.modules.sciTechnologyDemand.repository.SciTechnologyDemandRecordRepository;
import com.fzhucc.modules.sciTechnologyDemand.repository.SciTechnologyDemandRepository;
import com.fzhucc.modules.sciTechnologyDemand.service.mapstruct.SciTechnologyDemandInfoMapper;
import com.fzhucc.modules.sciTechnologyDemand.service.mapstruct.SciTechnologyDemandMapper;
import com.fzhucc.modules.sciTechnologyDemand.service.mapstruct.SciTechnologyDemandRecordMapper;
import com.fzhucc.modules.system.domain.User;
import com.fzhucc.modules.system.domain.UserSmall;
import com.fzhucc.modules.system.repository.UserRepository;
import com.fzhucc.modules.system.repository.UserSmallRepository;
import com.fzhucc.modules.system.service.DictDetailService;
import com.fzhucc.modules.system.service.DictService;
import com.fzhucc.modules.system.service.dto.DictDetailDto;
import com.fzhucc.modules.system.service.dto.DictDto;
import com.fzhucc.modules.system.service.dto.DictQueryCriteria;
import com.fzhucc.utils.*;
import com.google.gson.Gson;
import lombok.RequiredArgsConstructor;
import com.fzhucc.modules.sciPersonnelInfo.service.mapstruct.SciPersonnelInfoMapper;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;

import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.*;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

/**
 * @author yyg
 * @website https://eladmin.vip
 * @description 服务实现
 * @date 2023-11-30
 **/
@Service
@RequiredArgsConstructor
public class SciPersonnelInfoService {

    private static String authUrl = "https://portal-service.fujiansme.com/api/auth/jwt/v2/clientToken?password=zJJ*wA4hFxg&userName=SCZXGXT";
    private static String msgUrl = "https://portal-service.fujiansme.com/api/client/request/system/third";
    private Logger logger = LoggerFactory.getLogger(SciPersonnelInfoService.class);

    private final SciPersonnelInfoRepository sciPersonnelInfoRepository;

    private final TechnologyReTypeRepository technologyReTypeRepository;

    private final SciTechnologyDemandRecordRepository sciTechnologyDemandRecordRepository;

    private final SciTechnologyDemandRecordMapper sciTechnologyDemandRecordMapper;

    private final SciTechnologyDemandRepository sciTechnologyDemandRepository;

    private final SciTechnologyDemandMapper sciTechnologyDemandMapper;

    private final ModelDemandAuditLogRepository modelDemandAuditLogRepository;

    private final SciExpertReservationRepository expertReservationRepository;

    private final SciExpertConsultationConfigRepository expertConsultationConfigRepository;

    private final SciExpertOfflineConfigRepository expertOfflineConfigRepository;

    private final SciPersonnelInfoWeRepository sciPersonnelInfoWeRepository;

    private final SciPersonnelInfoLessonRepository sciPersonnelInfoLessonRepository;

    private final SciStudioRepository sciStudioRepository;

    private final SciPersonnelInfoResultRepository sciPersonnelInfoResultRepository;

    private final SciEnterpriseRepository sciEnterpriseRepository;

    private final SciEnterpriseMapper sciEnterpriseMapper;
    private final SciPersonnelInfoMapper sciPersonnelInfoMapper;
    private final SciStudioInfoRepository sciStudioInfoRepository;

    private final SciStudioImgRepository sciStudioImgRepository;

    private final DictService dictService;

    private final DictDetailService dictDetailService;

    private final UserRepository userRepository;

    private final SciStudioMapper sciStudioMapper;

    private final SciStudioInfoMapper sciStudioInfoMapper;

    private final SciStudioImgMapper sciStudioImgMapper;

    private final SciTechnologyDemandInfoRepository sciTechnologyDemandInfoRepository;

    private final SciTechnologyDemandInfoMapper sciTechnologyDemandInfoMapper;

    private final SciCxResultRepository sciCxResultRepository;

    private final SciCxResultInfoMapper sciCxResultInfoMapper;

    private final SciCxResultInfoRepository sciCxResultInfoRepository;

    private final SciCxResultMapper sciCxResultMapper;

    private final HotRepository hotRepository;

    private final HotRecordRepository hotRecordRepository;

    private final MsgRepository msgRepository;

    private final UserSmallRepository userSmallRepository;

    private final SciPersonnelInfoMateRepository sciPersonnelInfoMateRepository;

    private final FenRecordLogService fenRecordLogService;

    private final LoveModelRecordRepository loveModelRecordRepository;

    @Value("${org.area.all}")
    public String all;

    @Value("${org.area.all2}")
    public String all2;

    @Value("${fen.type.lm}")
    public String lm;

    @Value("${sci.log.demand}")
    public String demand;

    @Value("${sci.audit.qxdsh}")
    public String qxdsh;

    @Value("${sci.audit.caogao}")
    public String caogao;

    @Value("${zn.account}")
    public String account;

    @Value("${zn.pwd}")
    public String pwd;

    @Value("${zn.tokenUrl}")
    public String tokenUrl;

    @Value("${sci.log.cxcg}")
    public String cxcg;

    @Value("${sci.audit.sjdsh}")
    public String sjdsh;

    @Value("${sci.audit.shtg}")
    public String shtg;

    @Value("${sci.audit.bh}")
    public String bh;

    @Value("${sci.log.model}")
    public String model;

    @Value("${sci.stage.quPass}")
    public String quPass;

    @Value("${sci.stage.quNoPass}")
    public String quNoPass;

    @Value("${sci.stage.cityPass}")
    public String cityPass;

    @Value("${sci.log.gzs}")
    public String gzs;

    @Value("${sci.stage.cityNoPass}")
    public String cityNoPass;

    @Value("${org.area.pt}")
    public String pt;

    @Value("${org.area.pt2}")
    public String pt2;

    @Value("${org.area.qz}")
    public String qz;

    @Value("${org.area.qz2}")
    public String qz2;

    @Value("${org.area.xm}")
    public String xm;

    @Value("${org.area.xm2}")
    public String xm2;

    @Value("${org.area.zz}")
    public String zz;

    @Value("${org.area.zz2}")
    public String zz2;

    @Value("${org.area.ly}")
    public String ly;

    @Value("${org.area.ly2}")
    public String ly2;

    @Value("${org.area.sm}")
    public String sm;

    @Value("${org.area.sm2}")
    public String sm2;

    @Value("${org.area.np}")
    public String np;

    @Value("${org.area.np2}")
    public String np2;

    @Value("${org.area.nd}")
    public String nd;

    @Value("${org.area.nd2}")
    public String nd2;

    @Value("${org.area.ptang}")
    public String ptang;

    @Value("${org.area.ptang2}")
    public String ptang2;

    @Value("${org.area.fz}")
    public String fz;

    @Value("${org.area.fz2}")
    public String fz2;

    public List<SciPersonnelInfo> queryModel() {
        List<SciPersonnelInfo> model = sciPersonnelInfoRepository.findNormalWithOutIsShow(shtg);
        return model;
    }

    public Map<String, Object> queryModelPage(SciPersonnelInfoQueryCriteria criteria, Pageable pageable) {
        criteria.setIsDelete(0);
        criteria.setAuditStatus(shtg);
        Page<SciPersonnelInfo> page = sciPersonnelInfoRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder), pageable);
        Page<SciPersonnelInfoDto> map = page.map(sciPersonnelInfoMapper::toDto);
        return PageUtil.toPage(map);
    }

    public Map<String, Object> queryAll(SciPersonnelInfoQueryCriteria criteria, Pageable pageable) {
        //管理端根据登录用户地区
        String str = setCriteria(criteria);
        if (str == null) {
            if (criteria.getOrgAreas() != null && criteria.getOrgAreas().length > 0) {
                //表示为省总账号 且输入模糊查询
                //TODO 即查询参数有参数  省总账号查具体模糊查询
                String[] orgAreas = criteria.getOrgAreas();
                criteria.setOrgArea(orgAreas[orgAreas.length - 1]);
            } else {
                criteria.setOrgArea(str);
            }
        } else {
            //TODO 添加判断第三级   是否包含在第二级中   则采用第三级的查询
            if (criteria.getOrgAreas() != null && criteria.getOrgAreas().length == 3) {
                if (str.contains(criteria.getOrgAreas()[1])) {
                    criteria.setOrgArea(criteria.getOrgAreas()[2]);
                }
            } else {
                criteria.setOrgArea(str);
            }
        }
        criteria.setIsDelete(0);
        criteria.setOrgAreas(null);
        Page<SciPersonnelInfo> page = sciPersonnelInfoRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder), pageable);
        Page<SciPersonnelInfoDto> map = page.map(sciPersonnelInfoMapper::toDto);
        List<SciPersonnelInfoDto> list = map.getContent();
        if (list != null && list.size() > 0) {
            for (SciPersonnelInfoDto sciPersonnelInfoDto : list) {
                //TODO 看是否登录没登录都返回未收藏
                try {
                    Long userId = SecurityUtils.getCurrentUserId();
                    if (userId != null) {
                        List<LoveModelRecord> res = loveModelRecordRepository.findByModelIdAndUserId(userId, sciPersonnelInfoDto.getId());
                        if (res != null && res.size() > 0) {
                            sciPersonnelInfoDto.setIsLove(true);
                        } else {
                            sciPersonnelInfoDto.setIsLove(false);
                        }
                    } else {
                        sciPersonnelInfoDto.setIsLove(false);
                    }
                } catch (Exception e) {
                    sciPersonnelInfoDto.setIsLove(false);
                }
                //TODO 收藏的人数
                int loves = loveModelRecordRepository.findByModelId(sciPersonnelInfoDto.getId());
                sciPersonnelInfoDto.setLove(loves);

                String matype = sciPersonnelInfoDto.getMatype();
                if (matype != null && matype.contains(";")) {
                    String[] array = matype.split(";");
                    sciPersonnelInfoDto.setMatypes(array);
                } else {
                    String[] array = {};
                    sciPersonnelInfoDto.setMatypes(array);
                }
                Integer qyId = sciPersonnelInfoDto.getQyId();
                if (qyId != null) {
                    Optional<SciEnterprise> res = sciEnterpriseRepository.findById(qyId);
                    if (res.isPresent()) {
                        SciEnterprise sciEnterprise = res.get();
                        sciPersonnelInfoDto.setQy(sciEnterpriseMapper.toDto(sciEnterprise));
                    }
                }
                String keyword = sciPersonnelInfoDto.getKeyword();
                if (keyword != null && keyword.contains(";")) {
                    String[] array = keyword.split(";");
                    sciPersonnelInfoDto.setKeywords(array);
                } else {
                    String[] array = {};
                    sciPersonnelInfoDto.setKeywords(array);
                }
                String retype = sciPersonnelInfoDto.getRetype();
                if (retype != null && retype.contains(";")) {
                    String[] array = retype.split(";");
                    sciPersonnelInfoDto.setRetypes(array);
                } else {
                    String[] array = {};
                    sciPersonnelInfoDto.setRetypes(array);
                }
                String orgArea = sciPersonnelInfoDto.getOrgArea();
                if (orgArea != null && orgArea.contains(";")) {
                    String[] array = orgArea.split(";");
                    sciPersonnelInfoDto.setOrgAreas(array);
                } else {
                    String[] array = {};
                    sciPersonnelInfoDto.setOrgAreas(array);
                }

                String companyArea = sciPersonnelInfoDto.getCompanyarea();
                if (companyArea != null && companyArea.contains(";")) {
                    String[] array = companyArea.split(";");
                    sciPersonnelInfoDto.setCompanyAreas(array);
                } else {
                    String[] array = {};
                    sciPersonnelInfoDto.setCompanyAreas(array);
                }

                Integer id = sciPersonnelInfoDto.getId();
                List<SciPersonnelInfoResult> results = sciPersonnelInfoResultRepository.findBySpId(id);
                sciPersonnelInfoDto.setListResult(results);
                List<SciPersonnelInfoLesson> list2 = sciPersonnelInfoLessonRepository.findBySpId(id);
                sciPersonnelInfoDto.setListLesson(list2);
                List<SciPersonnelInfoWe> list3 = sciPersonnelInfoWeRepository.findBySpId(id);
                sciPersonnelInfoDto.setListWe(list3);
                List<ModelDemandAuditLog> modelDemandAuditLogs = modelDemandAuditLogRepository.findBySportdIdWithType(id, model);
                sciPersonnelInfoDto.setListModelDemandAuditLog(modelDemandAuditLogs);

                //TODO 返回工作室信息
                List<SciStudio> listStudio = sciStudioRepository.findByMdId(id, shtg);
                List<SciStudioDto> sciStudioDtos = sciStudioMapper.toDto(listStudio);
                if (sciStudioDtos != null && sciStudioDtos.size() > 0) {
                    for (SciStudioDto dto : sciStudioDtos) {
                        //TODO返回工作室信息
                        String orgArea2 = dto.getOrgArea();
                        if (orgArea2 != null && orgArea2.contains(";")) {
                            String[] array = orgArea2.split(";");
                            dto.setOrgAreas(array);
                        } else {
                            String[] array = {};
                            dto.setOrgAreas(array);
                        }

                        String type = dto.getType();
                        if (type != null && type.contains(";")) {
                            String[] array = type.split(";");
                            dto.setTypes(array);
                        } else {
                            String[] array = {};
                            dto.setTypes(array);
                        }

                        List<SciStudioInfo> lists = sciStudioInfoRepository.findByStId(dto.getId());
                        dto.setListSciStudioInfo(sciStudioInfoMapper.toDto(lists));

                        List<SciStudioImg> lists2 = sciStudioImgRepository.findByStId(dto.getId());
                        List<SciStudioImgDto> sciStudioImgDtos = sciStudioImgMapper.toDto(lists2);
                        List<String> imgs = new ArrayList<String>();
                        if (sciStudioImgDtos != null && sciStudioImgDtos.size() > 0) {
                            for (SciStudioImgDto dto2 : sciStudioImgDtos) {
                                imgs.add(dto2.getPic());
                            }
                        }
                        dto.setListSciStudioImg(imgs);

                        List<ModelDemandAuditLog> modelDemandAuditLogs2 = modelDemandAuditLogRepository.findBySportdIdWithType(dto.getId(), gzs);
                        dto.setListModelDemandAuditLog(modelDemandAuditLogs2);

                        List<SciCxResult> list5 = sciCxResultRepository.findByStudioId(dto.getId());
                        if (list5 != null) {
                            List<SciCxResultDto> sciCxResultDtos = sciCxResultMapper.toDto(list5);
                            if (sciCxResultDtos != null && sciCxResultDtos.size() > 0) {
                                for (SciCxResultDto dto2 : sciCxResultDtos) {
                                    String orgArea3 = dto2.getOrgArea();
                                    if (orgArea3 != null && orgArea3.contains(";")) {
                                        String[] array = orgArea3.split(";");
                                        dto2.setOrgAreas(array);
                                    } else {
                                        String[] array = {};
                                        dto2.setOrgAreas(array);
                                    }
                                    List<ModelDemandAuditLog> modelDemandAuditLogs3 = modelDemandAuditLogRepository.findBySportdIdWithType(dto2.getId(), cxcg);
                                    dto2.setListModelDemandAuditLog(modelDemandAuditLogs3);
                                    List<SciCxResultInfo> lists5 = sciCxResultInfoRepository.findByCxId(dto2.getId());
                                    dto2.setListSciCxResultInfo(sciCxResultInfoMapper.toDto(lists5));
                                }
                            }
                            dto.setListCxcg(sciCxResultDtos);
                        }
                    }
                }
                sciPersonnelInfoDto.setListStudios(sciStudioDtos);


                List<SciExpertConfigListsDto> result = new ArrayList<SciExpertConfigListsDto>();
                List<SciExpertConsultationConfig> lists = expertConsultationConfigRepository.findByExpertId(sciPersonnelInfoDto.getId());
                if (lists != null && lists.size() > 0) {
                    for (SciExpertConsultationConfig res : lists) {
                        SciExpertConfigListsDto expertConfigListsDto = new SciExpertConfigListsDto();
                        List<String> res3 = new ArrayList<String>();
                        Integer id1 = res.getId();
                        expertConfigListsDto.setId(id1);
                        String timeSlot = res.getTimeSlot();
                        if (timeSlot != null && !timeSlot.equals("")) {
                            String[] split = timeSlot.split(";");
                            res3.add(split[0]);
                            res3.add(split[1]);
                        }
                        expertConfigListsDto.setList(res3);
                        result.add(expertConfigListsDto);
                    }
                }
                sciPersonnelInfoDto.setListConsultation(result);


                List<SciExpertConfigLists2Dto> result2 = new ArrayList<SciExpertConfigLists2Dto>();
                List<SciExpertOfflineConfig> lists2 = expertOfflineConfigRepository.findByExpertId(sciPersonnelInfoDto.getId());
                if (lists2 != null && lists2.size() > 0) {
                    for (SciExpertOfflineConfig res : lists2) {
                        SciExpertConfigLists2Dto expertConfigLists2Dto = new SciExpertConfigLists2Dto();
                        List<String> res4 = new ArrayList<String>();
                        Integer id1 = res.getId();
                        expertConfigLists2Dto.setId(id1);
                        String timeSlot = res.getTimeSlot();
                        if (timeSlot != null && !timeSlot.equals("")) {
                            String[] split = timeSlot.split(";");
                            res4.add(split[0]);
                            res4.add(split[1]);
                        }
                        expertConfigLists2Dto.setList(res4);
                        expertConfigLists2Dto.setAddress(res.getAddress());
                        expertConfigLists2Dto.setDay(res.getDay());
                        expertConfigLists2Dto.setLimitsCount(res.getLimitsCount());

                        //TODO 计算报名剩余人数
                        Integer limitsCount = expertConfigLists2Dto.getLimitsCount();
                        List<SciExpertReservation> listExpertReservation = expertReservationRepository.findByExpertOfflineId(res.getId());
                        if (listExpertReservation != null) {
                            int last = limitsCount - listExpertReservation.size();
                            expertConfigLists2Dto.setResidueMan(last);
                        } else {
                            expertConfigLists2Dto.setResidueMan(limitsCount);
                        }
                        result2.add(expertConfigLists2Dto);
                    }
                }
                sciPersonnelInfoDto.setListOff(result2);

                //todo 被选中的需求列表
                List<SciPersonnelInfoMate> isSelect = sciPersonnelInfoMateRepository.findIsSelect(sciPersonnelInfoDto.getId());
                List<SciTechnologyDemandDto> listSelectDemands = new ArrayList<>();
                if (isSelect != null && isSelect.size() > 0) {
                    for (SciPersonnelInfoMate sciPersonnelInfoMate : isSelect) {
                        Integer tdId = sciPersonnelInfoMate.getTdId();
                        Optional<SciTechnologyDemand> ops = sciTechnologyDemandRepository.findById(tdId);
                        if (ops.isPresent()) {
                            SciTechnologyDemandDto sciTechnologyDemandDto = sciTechnologyDemandMapper.toDto(ops.get());


                            List<SciTechnologyDemandInfo> list6 = sciTechnologyDemandInfoRepository.findByTdId(sciTechnologyDemandDto.getId());
                            List<SciTechnologyDemandInfoDto> list7 = sciTechnologyDemandInfoMapper.toDto(list6);
                            if (list7 != null && list7.size() > 0) {
                                for (SciTechnologyDemandInfoDto info : list7) {
                                    String maType = info.getMaType();
                                    if (maType != null && maType.contains(";")) {
                                        String[] array = maType.split(";");
                                        info.setMaTypes(array);
                                    } else {
                                        String[] array = {};
                                        info.setMaTypes(array);
                                    }
                                }
                            }
                            sciTechnologyDemandDto.setListSdInfo(list7);

                            List<SciTechnologyDemandRecord> list9 = sciTechnologyDemandRecordRepository.findByTdId(sciTechnologyDemandDto.getId());
                            List<SciTechnologyDemandRecordDto> sciTechnologyDemandRecordDtos = sciTechnologyDemandRecordMapper.toDto(list9);
                            sciTechnologyDemandDto.setListRecord(sciTechnologyDemandRecordDtos);


                            String matype5 = sciTechnologyDemandDto.getMaType();
                            if (matype5 != null && matype5.contains(";")) {
                                String[] array = matype5.split(";");
                                sciTechnologyDemandDto.setMatypes(array);
                            } else {
                                String[] array = {};
                                sciTechnologyDemandDto.setMatypes(array);
                            }
                            String keyword5 = sciTechnologyDemandDto.getKeyword();
                            if (keyword5 != null && keyword5.contains(";")) {
                                String[] array = keyword5.split(";");
                                sciTechnologyDemandDto.setKeywords(array);
                            } else {
                                String[] array = {};
                                sciTechnologyDemandDto.setKeywords(array);
                            }
                            String orgArea5 = sciTechnologyDemandDto.getOrgArea();
                            if (orgArea5 != null && orgArea5.contains(";")) {
                                String[] array = orgArea5.split(";");
                                sciTechnologyDemandDto.setOrgAreas(array);
                            } else {
                                String[] array = {};
                                sciTechnologyDemandDto.setOrgAreas(array);
                            }
                            List<ModelDemandAuditLog> modelDemandAuditLogs5 = modelDemandAuditLogRepository.findBySportdIdWithType(sciTechnologyDemandDto.getId(), demand);
                            sciTechnologyDemandDto.setListModelDemandAuditLog(modelDemandAuditLogs5);

                            listSelectDemands.add(sciTechnologyDemandDto);
                        }
                    }
                }
                sciPersonnelInfoDto.setListSelectDemands(listSelectDemands);
            }
        }
        return PageUtil.toPage(map);
    }

    public Map<String, Object> queryAllh5(SciPersonnelInfoQueryCriteria criteria, Pageable pageable) {
        //TODO 增加访问分数
        try {
            fenRecordLogService.insertUserFen(lm);
        } catch (Exception e) {

        }

        //TODO 首页计数  并记录数据
        if (criteria.getOrgArea().contains(all) || criteria.getOrgArea().contains(all2)) {
            Optional<Hot> res = hotRepository.findById(1);
            if (res.isPresent()) {
                Hot hot = res.get();
                Integer sheng = hot.getSheng();
                hot.setSheng(sheng + 1);
                hotRepository.save(hot);
                HotRecord hotRecord = new HotRecord();
                hotRecord.setInTime(new Timestamp(new Date().getTime()));
                hotRecord.setOrgArea(criteria.getOrgArea());
                hotRecordRepository.save(hotRecord);
            }
        }

        if (criteria.getOrgArea().equals(fz) || criteria.getOrgArea().equals(fz2)) {
            Optional<Hot> res = hotRepository.findById(1);
            if (res.isPresent()) {
                Hot hot = res.get();
                Integer fz1 = hot.getFz();
                hot.setFz(fz1 + 1);
                hotRepository.save(hot);
                HotRecord hotRecord = new HotRecord();
                hotRecord.setInTime(new Timestamp(new Date().getTime()));
                hotRecord.setOrgArea(criteria.getOrgArea());
                hotRecordRepository.save(hotRecord);
            }
        }

        if (criteria.getOrgArea().equals(pt) || criteria.getOrgArea().equals(pt2)) {
            Optional<Hot> res = hotRepository.findById(1);
            if (res.isPresent()) {
                Hot hot = res.get();
                Integer pt1 = hot.getPt();
                hot.setPt(pt1 + 1);
                hotRepository.save(hot);
                HotRecord hotRecord = new HotRecord();
                hotRecord.setInTime(new Timestamp(new Date().getTime()));
                hotRecord.setOrgArea(criteria.getOrgArea());
                hotRecordRepository.save(hotRecord);
            }
        }

        if (criteria.getOrgArea().equals(qz) || criteria.getOrgArea().equals(qz2)) {
            Optional<Hot> res = hotRepository.findById(1);
            if (res.isPresent()) {
                Hot hot = res.get();
                Integer qz1 = hot.getQz();
                hot.setQz(qz1 + 1);
                hotRepository.save(hot);
                HotRecord hotRecord = new HotRecord();
                hotRecord.setInTime(new Timestamp(new Date().getTime()));
                hotRecord.setOrgArea(criteria.getOrgArea());
                hotRecordRepository.save(hotRecord);
            }
        }

        if (criteria.getOrgArea().equals(xm) || criteria.getOrgArea().equals(xm2)) {
            Optional<Hot> res = hotRepository.findById(1);
            if (res.isPresent()) {
                Hot hot = res.get();
                Integer xm1 = hot.getXm();
                hot.setXm(xm1 + 1);
                hotRepository.save(hot);
                HotRecord hotRecord = new HotRecord();
                hotRecord.setInTime(new Timestamp(new Date().getTime()));
                hotRecord.setOrgArea(criteria.getOrgArea());
                hotRecordRepository.save(hotRecord);
            }
        }

        if (criteria.getOrgArea().equals(zz) || criteria.getOrgArea().equals(zz2)) {
            Optional<Hot> res = hotRepository.findById(1);
            if (res.isPresent()) {
                Hot hot = res.get();
                Integer zz1 = hot.getZz();
                hot.setZz(zz1 + 1);
                hotRepository.save(hot);
                HotRecord hotRecord = new HotRecord();
                hotRecord.setInTime(new Timestamp(new Date().getTime()));
                hotRecord.setOrgArea(criteria.getOrgArea());
                hotRecordRepository.save(hotRecord);
            }
        }

        if (criteria.getOrgArea().equals(ly) || criteria.getOrgArea().equals(ly2)) {
            Optional<Hot> res = hotRepository.findById(1);
            if (res.isPresent()) {
                Hot hot = res.get();
                Integer ly1 = hot.getLy();
                hot.setLy(ly1 + 1);
                hotRepository.save(hot);
                HotRecord hotRecord = new HotRecord();
                hotRecord.setInTime(new Timestamp(new Date().getTime()));
                hotRecord.setOrgArea(criteria.getOrgArea());
                hotRecordRepository.save(hotRecord);
            }
        }

        if (criteria.getOrgArea().equals(sm) || criteria.getOrgArea().equals(sm2)) {
            Optional<Hot> res = hotRepository.findById(1);
            if (res.isPresent()) {
                Hot hot = res.get();
                Integer sm1 = hot.getSm();
                hot.setSm(sm1 + 1);
                hotRepository.save(hot);
                HotRecord hotRecord = new HotRecord();
                hotRecord.setInTime(new Timestamp(new Date().getTime()));
                hotRecord.setOrgArea(criteria.getOrgArea());
                hotRecordRepository.save(hotRecord);
            }
        }

        if (criteria.getOrgArea().equals(np) || criteria.getOrgArea().equals(np2)) {
            Optional<Hot> res = hotRepository.findById(1);
            if (res.isPresent()) {
                Hot hot = res.get();
                Integer np1 = hot.getNp();
                hot.setNp(np1 + 1);
                hotRepository.save(hot);
                HotRecord hotRecord = new HotRecord();
                hotRecord.setInTime(new Timestamp(new Date().getTime()));
                hotRecord.setOrgArea(criteria.getOrgArea());
                hotRecordRepository.save(hotRecord);
            }
        }

        if (criteria.getOrgArea().equals(nd) || criteria.getOrgArea().equals(nd2)) {
            Optional<Hot> res = hotRepository.findById(1);
            if (res.isPresent()) {
                Hot hot = res.get();
                Integer nd1 = hot.getNd();
                hot.setNd(nd1 + 1);
                hotRepository.save(hot);
                HotRecord hotRecord = new HotRecord();
                hotRecord.setInTime(new Timestamp(new Date().getTime()));
                hotRecord.setOrgArea(criteria.getOrgArea());
                hotRecordRepository.save(hotRecord);
            }
        }

        if (criteria.getOrgArea().equals(ptang) || criteria.getOrgArea().equals(ptang2)) {
            Optional<Hot> res = hotRepository.findById(1);
            if (res.isPresent()) {
                Hot hot = res.get();
                Integer ptang1 = hot.getPtang();
                hot.setPtang(ptang1 + 1);
                hotRepository.save(hot);
                HotRecord hotRecord = new HotRecord();
                hotRecord.setInTime(new Timestamp(new Date().getTime()));
                hotRecord.setOrgArea(criteria.getOrgArea());
                hotRecordRepository.save(hotRecord);
            }
        }


        criteria.setIsDelete(0);
        if (criteria.getOrgArea() != null && criteria.getOrgArea().equals(all)) {
            //h5的直接传orgArea
            criteria.setOrgArea(null);
        }

        Page<SciPersonnelInfo> page = sciPersonnelInfoRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder), pageable);
        Page<SciPersonnelInfoDto> map = page.map(sciPersonnelInfoMapper::toDto);
        List<SciPersonnelInfoDto> list = map.getContent();
        if (list != null && list.size() > 0) {
            for (SciPersonnelInfoDto sciPersonnelInfoDto : list) {
                //TODO 看是否登录没登录都返回未收藏
                try {
                    Long userId = SecurityUtils.getCurrentUserId();
                    if (userId != null) {
                        List<LoveModelRecord> res = loveModelRecordRepository.findByModelIdAndUserId(userId, sciPersonnelInfoDto.getId());
                        if (res != null && res.size() > 0) {
                            sciPersonnelInfoDto.setIsLove(true);
                        } else {
                            sciPersonnelInfoDto.setIsLove(false);
                        }
                    } else {
                        sciPersonnelInfoDto.setIsLove(false);
                    }
                } catch (Exception e) {
                    sciPersonnelInfoDto.setIsLove(false);
                }
                //TODO 收藏的人数
                int loves = loveModelRecordRepository.findByModelId(sciPersonnelInfoDto.getId());
                sciPersonnelInfoDto.setLove(loves);

                String matype = sciPersonnelInfoDto.getMatype();
                if (matype != null && matype.contains(";")) {
                    String[] array = matype.split(";");
                    sciPersonnelInfoDto.setMatypes(array);
                } else {
                    String[] array = {};
                    sciPersonnelInfoDto.setMatypes(array);
                }
                Integer qyId = sciPersonnelInfoDto.getQyId();
                if (qyId != null) {
                    Optional<SciEnterprise> res = sciEnterpriseRepository.findById(qyId);
                    if (res.isPresent()) {
                        SciEnterprise sciEnterprise = res.get();
                        sciPersonnelInfoDto.setQy(sciEnterpriseMapper.toDto(sciEnterprise));
                    }
                }
                String keyword = sciPersonnelInfoDto.getKeyword();
                if (keyword != null && keyword.contains(";")) {
                    String[] array = keyword.split(";");
                    sciPersonnelInfoDto.setKeywords(array);
                } else {
                    String[] array = {};
                    sciPersonnelInfoDto.setKeywords(array);
                }
                String retype = sciPersonnelInfoDto.getRetype();
                if (retype != null && retype.contains(";")) {
                    String[] array = retype.split(";");
                    sciPersonnelInfoDto.setRetypes(array);
                } else {
                    String[] array = {};
                    sciPersonnelInfoDto.setRetypes(array);
                }
                String orgArea = sciPersonnelInfoDto.getOrgArea();
                if (orgArea != null && orgArea.contains(";")) {
                    String[] array = orgArea.split(";");
                    sciPersonnelInfoDto.setOrgAreas(array);
                } else {
                    String[] array = {};
                    sciPersonnelInfoDto.setOrgAreas(array);
                }

                String companyArea = sciPersonnelInfoDto.getCompanyarea();
                if (companyArea != null && companyArea.contains(";")) {
                    String[] array = companyArea.split(";");
                    sciPersonnelInfoDto.setCompanyAreas(array);
                } else {
                    String[] array = {};
                    sciPersonnelInfoDto.setCompanyAreas(array);
                }

                Integer id = sciPersonnelInfoDto.getId();
                List<SciPersonnelInfoResult> results = sciPersonnelInfoResultRepository.findBySpId(id);
                sciPersonnelInfoDto.setListResult(results);
                List<SciPersonnelInfoLesson> list2 = sciPersonnelInfoLessonRepository.findBySpId(id);
                sciPersonnelInfoDto.setListLesson(list2);
                List<SciPersonnelInfoWe> list3 = sciPersonnelInfoWeRepository.findBySpId(id);
                sciPersonnelInfoDto.setListWe(list3);
                List<ModelDemandAuditLog> modelDemandAuditLogs = modelDemandAuditLogRepository.findBySportdIdWithType(id, model);
                sciPersonnelInfoDto.setListModelDemandAuditLog(modelDemandAuditLogs);

                //TODO 返回工作室信息
                List<SciStudio> listStudio = sciStudioRepository.findByMdId(id, shtg);
                List<SciStudioDto> sciStudioDtos = sciStudioMapper.toDto(listStudio);
                if (sciStudioDtos != null && sciStudioDtos.size() > 0) {
                    for (SciStudioDto dto : sciStudioDtos) {
                        //TODO返回工作室信息
                        String orgArea2 = dto.getOrgArea();
                        if (orgArea2 != null && orgArea2.contains(";")) {
                            String[] array = orgArea2.split(";");
                            dto.setOrgAreas(array);
                        } else {
                            String[] array = {};
                            dto.setOrgAreas(array);
                        }

                        String type = dto.getType();
                        if (type != null && type.contains(";")) {
                            String[] array = type.split(";");
                            dto.setTypes(array);
                        } else {
                            String[] array = {};
                            dto.setTypes(array);
                        }

                        List<SciStudioInfo> lists = sciStudioInfoRepository.findByStId(dto.getId());
                        dto.setListSciStudioInfo(sciStudioInfoMapper.toDto(lists));

                        List<SciStudioImg> lists2 = sciStudioImgRepository.findByStId(dto.getId());
                        List<SciStudioImgDto> sciStudioImgDtos = sciStudioImgMapper.toDto(lists2);
                        List<String> imgs = new ArrayList<String>();
                        if (sciStudioImgDtos != null && sciStudioImgDtos.size() > 0) {
                            for (SciStudioImgDto dto2 : sciStudioImgDtos) {
                                imgs.add(dto2.getPic());
                            }
                        }
                        dto.setListSciStudioImg(imgs);

                        List<ModelDemandAuditLog> modelDemandAuditLogs2 = modelDemandAuditLogRepository.findBySportdIdWithType(dto.getId(), gzs);
                        dto.setListModelDemandAuditLog(modelDemandAuditLogs2);

                        List<SciCxResult> list5 = sciCxResultRepository.findByStudioId(dto.getId());
                        if (list5 != null) {
                            List<SciCxResultDto> sciCxResultDtos = sciCxResultMapper.toDto(list5);
                            if (sciCxResultDtos != null && sciCxResultDtos.size() > 0) {
                                for (SciCxResultDto dto2 : sciCxResultDtos) {
                                    String orgArea3 = dto2.getOrgArea();
                                    if (orgArea3 != null && orgArea3.contains(";")) {
                                        String[] array = orgArea3.split(";");
                                        dto2.setOrgAreas(array);
                                    } else {
                                        String[] array = {};
                                        dto2.setOrgAreas(array);
                                    }
                                    List<ModelDemandAuditLog> modelDemandAuditLogs3 = modelDemandAuditLogRepository.findBySportdIdWithType(dto2.getId(), cxcg);
                                    dto2.setListModelDemandAuditLog(modelDemandAuditLogs3);
                                    List<SciCxResultInfo> lists5 = sciCxResultInfoRepository.findByCxId(dto2.getId());
                                    dto2.setListSciCxResultInfo(sciCxResultInfoMapper.toDto(lists5));
                                }
                            }
                            dto.setListCxcg(sciCxResultDtos);
                        }
                    }
                }
                sciPersonnelInfoDto.setListStudios(sciStudioDtos);


                List<SciExpertConfigListsDto> result = new ArrayList<SciExpertConfigListsDto>();
                List<SciExpertConsultationConfig> lists = expertConsultationConfigRepository.findByExpertId(sciPersonnelInfoDto.getId());
                if (lists != null && lists.size() > 0) {
                    for (SciExpertConsultationConfig res : lists) {
                        SciExpertConfigListsDto expertConfigListsDto = new SciExpertConfigListsDto();
                        List<String> res3 = new ArrayList<String>();
                        Integer id1 = res.getId();
                        expertConfigListsDto.setId(id1);
                        String timeSlot = res.getTimeSlot();
                        if (timeSlot != null && !timeSlot.equals("")) {
                            String[] split = timeSlot.split(";");
                            res3.add(split[0]);
                            res3.add(split[1]);
                        }
                        expertConfigListsDto.setList(res3);
                        result.add(expertConfigListsDto);
                    }
                }
                sciPersonnelInfoDto.setListConsultation(result);


                List<SciExpertConfigLists2Dto> result2 = new ArrayList<SciExpertConfigLists2Dto>();
                List<SciExpertOfflineConfig> lists2 = expertOfflineConfigRepository.findByExpertId(sciPersonnelInfoDto.getId());
                if (lists2 != null && lists2.size() > 0) {
                    for (SciExpertOfflineConfig res : lists2) {
                        SciExpertConfigLists2Dto expertConfigLists2Dto = new SciExpertConfigLists2Dto();
                        List<String> res4 = new ArrayList<String>();
                        Integer id1 = res.getId();
                        expertConfigLists2Dto.setId(id1);
                        String timeSlot = res.getTimeSlot();
                        if (timeSlot != null && !timeSlot.equals("")) {
                            String[] split = timeSlot.split(";");
                            res4.add(split[0]);
                            res4.add(split[1]);
                        }
                        expertConfigLists2Dto.setList(res4);
                        expertConfigLists2Dto.setAddress(res.getAddress());
                        expertConfigLists2Dto.setDay(res.getDay());
                        expertConfigLists2Dto.setLimitsCount(res.getLimitsCount());

                        //TODO 计算报名剩余人数
                        Integer limitsCount = expertConfigLists2Dto.getLimitsCount();
                        List<SciExpertReservation> listExpertReservation = expertReservationRepository.findByExpertOfflineId(res.getId());
                        if (listExpertReservation != null) {
                            int last = limitsCount - listExpertReservation.size();
                            expertConfigLists2Dto.setResidueMan(last);
                        } else {
                            expertConfigLists2Dto.setResidueMan(limitsCount);
                        }
                        result2.add(expertConfigLists2Dto);
                    }
                }
                sciPersonnelInfoDto.setListOff(result2);


                //todo 被选中的需求列表
                List<SciPersonnelInfoMate> isSelect = sciPersonnelInfoMateRepository.findIsSelect(sciPersonnelInfoDto.getId());
                List<SciTechnologyDemandDto> listSelectDemands = new ArrayList<>();
                if (isSelect != null && isSelect.size() > 0) {
                    for (SciPersonnelInfoMate sciPersonnelInfoMate : isSelect) {
                        Integer tdId = sciPersonnelInfoMate.getTdId();
                        Optional<SciTechnologyDemand> ops = sciTechnologyDemandRepository.findById(tdId);
                        if (ops.isPresent()) {
                            SciTechnologyDemandDto sciTechnologyDemandDto = sciTechnologyDemandMapper.toDto(ops.get());


                            List<SciTechnologyDemandInfo> list6 = sciTechnologyDemandInfoRepository.findByTdId(sciTechnologyDemandDto.getId());
                            List<SciTechnologyDemandInfoDto> list7 = sciTechnologyDemandInfoMapper.toDto(list6);
                            if (list7 != null && list7.size() > 0) {
                                for (SciTechnologyDemandInfoDto info : list7) {
                                    String maType = info.getMaType();
                                    if (maType != null && maType.contains(";")) {
                                        String[] array = maType.split(";");
                                        info.setMaTypes(array);
                                    } else {
                                        String[] array = {};
                                        info.setMaTypes(array);
                                    }
                                }
                            }
                            sciTechnologyDemandDto.setListSdInfo(list7);

                            List<SciTechnologyDemandRecord> list9 = sciTechnologyDemandRecordRepository.findByTdId(sciTechnologyDemandDto.getId());
                            List<SciTechnologyDemandRecordDto> sciTechnologyDemandRecordDtos = sciTechnologyDemandRecordMapper.toDto(list9);
                            sciTechnologyDemandDto.setListRecord(sciTechnologyDemandRecordDtos);


                            String matype5 = sciTechnologyDemandDto.getMaType();
                            if (matype5 != null && matype5.contains(";")) {
                                String[] array = matype5.split(";");
                                sciTechnologyDemandDto.setMatypes(array);
                            } else {
                                String[] array = {};
                                sciTechnologyDemandDto.setMatypes(array);
                            }
                            String keyword5 = sciTechnologyDemandDto.getKeyword();
                            if (keyword5 != null && keyword5.contains(";")) {
                                String[] array = keyword5.split(";");
                                sciTechnologyDemandDto.setKeywords(array);
                            } else {
                                String[] array = {};
                                sciTechnologyDemandDto.setKeywords(array);
                            }
                            String orgArea5 = sciTechnologyDemandDto.getOrgArea();
                            if (orgArea5 != null && orgArea5.contains(";")) {
                                String[] array = orgArea5.split(";");
                                sciTechnologyDemandDto.setOrgAreas(array);
                            } else {
                                String[] array = {};
                                sciTechnologyDemandDto.setOrgAreas(array);
                            }
                            List<ModelDemandAuditLog> modelDemandAuditLogs5 = modelDemandAuditLogRepository.findBySportdIdWithType(sciTechnologyDemandDto.getId(), demand);
                            sciTechnologyDemandDto.setListModelDemandAuditLog(modelDemandAuditLogs5);

                            listSelectDemands.add(sciTechnologyDemandDto);
                        }
                    }
                }
                sciPersonnelInfoDto.setListSelectDemands(listSelectDemands);
            }
        }
        return PageUtil.toPage(map);
    }

    public List<SciPersonnelInfoDto> queryAllmy(SciPersonnelInfoQueryCriteria criteria) {
        //TODO 有传则用最后一个代替我的查询
        if (criteria.getOrgAreas() != null && criteria.getOrgAreas().length > 0) {
            String[] orgAreas = criteria.getOrgAreas();
            String csOrgArea = orgAreas[orgAreas.length - 1];
            criteria.setOrgArea(csOrgArea);
            criteria.setOrgAreas(null);
        }
        Long userId = SecurityUtils.getCurrentUserId();
        if (userId == null) {
            throw new BadRequestException("未找到登录用户");
        }
        criteria.setUserId(userId);
        criteria.setIsDelete(0);
        return sciPersonnelInfoMapper.toDto(sciPersonnelInfoRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder)));
    }


    public Map<String, Object> my(SciPersonnelInfoQueryCriteria criteria, Pageable pageable) {
        //TODO 有传则用最后一个代替我的查询
        if (criteria.getOrgAreas() != null && criteria.getOrgAreas().length > 0) {
            String[] orgAreas = criteria.getOrgAreas();
            String csOrgArea = orgAreas[orgAreas.length - 1];
            criteria.setOrgArea(csOrgArea);
            criteria.setOrgAreas(null);
        }
        Long userId = SecurityUtils.getCurrentUserId();
        if (userId == null) {
            throw new BadRequestException("未找到登录用户");
        }
        criteria.setUserId(userId);
        criteria.setIsDelete(0);
        Page<SciPersonnelInfo> page = sciPersonnelInfoRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder), pageable);
        Page<SciPersonnelInfoDto> map = page.map(sciPersonnelInfoMapper::toDto);
        List<SciPersonnelInfoDto> list = map.getContent();
        if (list != null && list.size() > 0) {
            for (SciPersonnelInfoDto sciPersonnelInfoDto : list) {
                //TODO 看是否登录没登录都返回未收藏
                try {
                    Long userId2 = SecurityUtils.getCurrentUserId();
                    if (userId2 != null) {
                        List<LoveModelRecord> res = loveModelRecordRepository.findByModelIdAndUserId(userId2, sciPersonnelInfoDto.getId());
                        if (res != null && res.size() > 0) {
                            sciPersonnelInfoDto.setIsLove(true);
                        } else {
                            sciPersonnelInfoDto.setIsLove(false);
                        }
                    } else {
                        sciPersonnelInfoDto.setIsLove(false);
                    }
                } catch (Exception e) {
                    sciPersonnelInfoDto.setIsLove(false);
                }
                //TODO 收藏的人数
                int loves = loveModelRecordRepository.findByModelId(sciPersonnelInfoDto.getId());
                sciPersonnelInfoDto.setLove(loves);

                String matype = sciPersonnelInfoDto.getMatype();
                if (matype != null && matype.contains(";")) {
                    String[] array = matype.split(";");
                    sciPersonnelInfoDto.setMatypes(array);
                } else {
                    String[] array = {};
                    sciPersonnelInfoDto.setMatypes(array);
                }
                Integer qyId = sciPersonnelInfoDto.getQyId();
                if (qyId != null) {
                    Optional<SciEnterprise> res = sciEnterpriseRepository.findById(qyId);
                    if (res.isPresent()) {
                        SciEnterprise sciEnterprise = res.get();
                        sciPersonnelInfoDto.setQy(sciEnterpriseMapper.toDto(sciEnterprise));
                    }
                }
                String retype = sciPersonnelInfoDto.getRetype();
                if (retype != null && retype.contains(";")) {
                    String[] array = retype.split(";");
                    sciPersonnelInfoDto.setRetypes(array);
                } else {
                    String[] array = {};
                    sciPersonnelInfoDto.setRetypes(array);
                }
                String keyword = sciPersonnelInfoDto.getKeyword();
                if (keyword != null && keyword.contains(";")) {
                    String[] array = keyword.split(";");
                    sciPersonnelInfoDto.setKeywords(array);
                } else {
                    String[] array = {};
                    sciPersonnelInfoDto.setKeywords(array);
                }
                String orgArea = sciPersonnelInfoDto.getOrgArea();
                if (orgArea != null && orgArea.contains(";")) {
                    String[] array = orgArea.split(";");
                    sciPersonnelInfoDto.setOrgAreas(array);
                } else {
                    String[] array = {};
                    sciPersonnelInfoDto.setOrgAreas(array);
                }

                String companyArea = sciPersonnelInfoDto.getCompanyarea();
                if (companyArea != null && companyArea.contains(";")) {
                    String[] array = companyArea.split(";");
                    sciPersonnelInfoDto.setCompanyAreas(array);
                } else {
                    String[] array = {};
                    sciPersonnelInfoDto.setCompanyAreas(array);
                }
                Integer id = sciPersonnelInfoDto.getId();
                List<SciPersonnelInfoResult> results = sciPersonnelInfoResultRepository.findBySpId(id);
                sciPersonnelInfoDto.setListResult(results);
                List<SciPersonnelInfoLesson> list2 = sciPersonnelInfoLessonRepository.findBySpId(id);
                sciPersonnelInfoDto.setListLesson(list2);
                List<SciPersonnelInfoWe> list3 = sciPersonnelInfoWeRepository.findBySpId(id);
                sciPersonnelInfoDto.setListWe(list3);

                //TODO 返回工作室信息
                List<SciStudio> listStudio = sciStudioRepository.findByMdId(id, shtg);
                List<SciStudioDto> sciStudioDtos = sciStudioMapper.toDto(listStudio);
                if (sciStudioDtos != null && sciStudioDtos.size() > 0) {
                    for (SciStudioDto dto : sciStudioDtos) {
                        //TODO返回工作室信息
                        String orgArea2 = dto.getOrgArea();
                        if (orgArea2 != null && orgArea2.contains(";")) {
                            String[] array = orgArea2.split(";");
                            dto.setOrgAreas(array);
                        } else {
                            String[] array = {};
                            dto.setOrgAreas(array);
                        }

                        String type = dto.getType();
                        if (type != null && type.contains(";")) {
                            String[] array = type.split(";");
                            dto.setTypes(array);
                        } else {
                            String[] array = {};
                            dto.setTypes(array);
                        }

                        List<SciStudioInfo> lists = sciStudioInfoRepository.findByStId(dto.getId());
                        dto.setListSciStudioInfo(sciStudioInfoMapper.toDto(lists));

                        List<SciStudioImg> lists2 = sciStudioImgRepository.findByStId(dto.getId());
                        List<SciStudioImgDto> sciStudioImgDtos = sciStudioImgMapper.toDto(lists2);
                        List<String> imgs = new ArrayList<String>();
                        if (sciStudioImgDtos != null && sciStudioImgDtos.size() > 0) {
                            for (SciStudioImgDto dto2 : sciStudioImgDtos) {
                                imgs.add(dto2.getPic());
                            }
                        }
                        dto.setListSciStudioImg(imgs);

                        List<ModelDemandAuditLog> modelDemandAuditLogs2 = modelDemandAuditLogRepository.findBySportdIdWithType(dto.getId(), gzs);
                        dto.setListModelDemandAuditLog(modelDemandAuditLogs2);

                        List<SciCxResult> list5 = sciCxResultRepository.findByStudioId(dto.getId());
                        if (list5 != null) {
                            List<SciCxResultDto> sciCxResultDtos = sciCxResultMapper.toDto(list5);
                            if (sciCxResultDtos != null && sciCxResultDtos.size() > 0) {
                                for (SciCxResultDto dto2 : sciCxResultDtos) {
                                    String orgArea3 = dto2.getOrgArea();
                                    if (orgArea3 != null && orgArea3.contains(";")) {
                                        String[] array = orgArea3.split(";");
                                        dto2.setOrgAreas(array);
                                    } else {
                                        String[] array = {};
                                        dto2.setOrgAreas(array);
                                    }
                                    List<ModelDemandAuditLog> modelDemandAuditLogs3 = modelDemandAuditLogRepository.findBySportdIdWithType(dto2.getId(), cxcg);
                                    dto2.setListModelDemandAuditLog(modelDemandAuditLogs3);
                                    List<SciCxResultInfo> lists5 = sciCxResultInfoRepository.findByCxId(dto2.getId());
                                    dto2.setListSciCxResultInfo(sciCxResultInfoMapper.toDto(lists5));
                                }
                            }
                            dto.setListCxcg(sciCxResultDtos);
                        }
                    }
                }
                sciPersonnelInfoDto.setListStudios(sciStudioDtos);

                List<ModelDemandAuditLog> modelDemandAuditLogs = modelDemandAuditLogRepository.findBySportdIdWithType(id, model);
                sciPersonnelInfoDto.setListModelDemandAuditLog(modelDemandAuditLogs);

                //todo 被选中的需求列表
                List<SciPersonnelInfoMate> isSelect = sciPersonnelInfoMateRepository.findIsSelect(sciPersonnelInfoDto.getId());
                List<SciTechnologyDemandDto> listSelectDemands = new ArrayList<>();
                if (isSelect != null && isSelect.size() > 0) {
                    for (SciPersonnelInfoMate sciPersonnelInfoMate : isSelect) {
                        Integer tdId = sciPersonnelInfoMate.getTdId();
                        Optional<SciTechnologyDemand> ops = sciTechnologyDemandRepository.findById(tdId);
                        if (ops.isPresent()) {
                            SciTechnologyDemandDto sciTechnologyDemandDto = sciTechnologyDemandMapper.toDto(ops.get());


                            List<SciTechnologyDemandInfo> list6 = sciTechnologyDemandInfoRepository.findByTdId(sciTechnologyDemandDto.getId());
                            List<SciTechnologyDemandInfoDto> list7 = sciTechnologyDemandInfoMapper.toDto(list6);
                            if (list7 != null && list7.size() > 0) {
                                for (SciTechnologyDemandInfoDto info : list7) {
                                    String maType = info.getMaType();
                                    if (maType != null && maType.contains(";")) {
                                        String[] array = maType.split(";");
                                        info.setMaTypes(array);
                                    } else {
                                        String[] array = {};
                                        info.setMaTypes(array);
                                    }
                                }
                            }
                            sciTechnologyDemandDto.setListSdInfo(list7);

                            List<SciTechnologyDemandRecord> list9 = sciTechnologyDemandRecordRepository.findByTdId(sciTechnologyDemandDto.getId());
                            List<SciTechnologyDemandRecordDto> sciTechnologyDemandRecordDtos = sciTechnologyDemandRecordMapper.toDto(list9);
                            sciTechnologyDemandDto.setListRecord(sciTechnologyDemandRecordDtos);


                            String matype5 = sciTechnologyDemandDto.getMaType();
                            if (matype5 != null && matype5.contains(";")) {
                                String[] array = matype5.split(";");
                                sciTechnologyDemandDto.setMatypes(array);
                            } else {
                                String[] array = {};
                                sciTechnologyDemandDto.setMatypes(array);
                            }
                            String keyword5 = sciTechnologyDemandDto.getKeyword();
                            if (keyword5 != null && keyword5.contains(";")) {
                                String[] array = keyword5.split(";");
                                sciTechnologyDemandDto.setKeywords(array);
                            } else {
                                String[] array = {};
                                sciTechnologyDemandDto.setKeywords(array);
                            }
                            String orgArea5 = sciTechnologyDemandDto.getOrgArea();
                            if (orgArea5 != null && orgArea5.contains(";")) {
                                String[] array = orgArea5.split(";");
                                sciTechnologyDemandDto.setOrgAreas(array);
                            } else {
                                String[] array = {};
                                sciTechnologyDemandDto.setOrgAreas(array);
                            }
                            List<ModelDemandAuditLog> modelDemandAuditLogs5 = modelDemandAuditLogRepository.findBySportdIdWithType(sciTechnologyDemandDto.getId(), demand);
                            sciTechnologyDemandDto.setListModelDemandAuditLog(modelDemandAuditLogs5);

                            listSelectDemands.add(sciTechnologyDemandDto);
                        }
                    }
                }
                sciPersonnelInfoDto.setListSelectDemands(listSelectDemands);
            }
        }
        return PageUtil.toPage(map);
    }

    //根据不同设置不同的部门查看
    public String setCriteria(SciPersonnelInfoQueryCriteria criteria) {
        Long userId = null;
        try {
            userId = SecurityUtils.getCurrentUserId();
        } catch (Exception e) {
            //throw new RuntimeException(e);
            String orgArea = criteria.getOrgArea();
            if (orgArea != null && (orgArea.equals(all) || orgArea.equals(all2))) { //如果等于福建省则查全部
                return null;
            }
        }
        if (userId != null) {
            Optional<User> userOptional = userRepository.findById(userId);
            User res = userOptional.get();
            if (res.getOrgArea() != null && (res.getOrgArea().equals(all) || res.getOrgArea().equals(all2))) {//用的org组织最高看全部
                return null;
            } else {
                return res.getOrgArea();//如果用户的权限不是福建省则 只能看到对应的组织
            }
        } else {
            return null;
        }
    }

    public String orgAreaReturn() {
        Long userId = SecurityUtils.getCurrentUserId();
        if (userId == null) {//未登录则外面传进来
            return "";
        } else {
            Optional<User> userOptional = userRepository.findById(userId);
            User res = userOptional.get();
            return res.getOrgArea();
        }
    }

    public List<SciPersonnelInfoDto> queryAll(SciPersonnelInfoQueryCriteria criteria) {
        //导出  如果有传则按传的数组 导出
        criteria.setIsDelete(0);
        String str = setCriteria(criteria);
        if (str == null) {
            if (criteria.getOrgAreas() != null && criteria.getOrgAreas().length > 0) {
                //表示为省总账号 且输入模糊查询
                //TODO 即查询参数有参数  省总账号查具体模糊查询
                String[] orgAreas = criteria.getOrgAreas();
                criteria.setOrgArea(orgAreas[orgAreas.length - 1]);
            } else {
                criteria.setOrgArea(str);
            }
        } else {
            //criteria.setOrgArea(str);
            //TODO 添加判断第三级   是否包含在第二级中   则采用第三级的查询
            if (criteria.getOrgAreas() != null && criteria.getOrgAreas().length == 3) {
                if (str.contains(criteria.getOrgAreas()[1])) {
                    criteria.setOrgArea(criteria.getOrgAreas()[2]);
                }
            } else {
                criteria.setOrgArea(str);
            }
        }
        return sciPersonnelInfoMapper.toDto(sciPersonnelInfoRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder)));
    }

    @Transactional
    public SciPersonnelInfoDto findById(Integer id) {
        //TODO 增加访问分数
        try {
            fenRecordLogService.insertUserFen(lm);
        } catch (Exception e) {

        }

        SciPersonnelInfo sciPersonnelInfo = sciPersonnelInfoRepository.findById(id).orElseGet(SciPersonnelInfo::new);
        ValidationUtil.isNull(sciPersonnelInfo.getId(), "SciPersonnelInfo", "id", id);
        //查询热度 +1
        Integer hot = sciPersonnelInfo.getHot();
        sciPersonnelInfo.setHot(hot + 1);
        SciPersonnelInfo save = sciPersonnelInfoRepository.save(sciPersonnelInfo);
        SciPersonnelInfoDto dto = sciPersonnelInfoMapper.toDto(save);

        List<SciExpertConfigListsDto> result = new ArrayList<SciExpertConfigListsDto>();
        List<SciExpertConsultationConfig> lists = expertConsultationConfigRepository.findByExpertId(dto.getId());
        if (lists != null && lists.size() > 0) {
            for (SciExpertConsultationConfig res : lists) {
                SciExpertConfigListsDto expertConfigListsDto = new SciExpertConfigListsDto();
                List<String> res3 = new ArrayList<String>();
                Integer id1 = res.getId();
                expertConfigListsDto.setId(id1);
                String timeSlot = res.getTimeSlot();
                if (timeSlot != null && !timeSlot.equals("")) {
                    String[] split = timeSlot.split(";");
                    res3.add(split[0]);
                    res3.add(split[1]);
                }
                expertConfigListsDto.setList(res3);
                result.add(expertConfigListsDto);
            }
        }
        dto.setListConsultation(result);


        List<SciExpertConfigLists2Dto> result2 = new ArrayList<SciExpertConfigLists2Dto>();
        List<SciExpertOfflineConfig> lists2 = expertOfflineConfigRepository.findByExpertId(dto.getId());
        if (lists2 != null && lists2.size() > 0) {
            for (SciExpertOfflineConfig res : lists2) {
                SciExpertConfigLists2Dto expertConfigLists2Dto = new SciExpertConfigLists2Dto();
                List<String> res4 = new ArrayList<String>();
                Integer id1 = res.getId();
                expertConfigLists2Dto.setId(id1);
                String timeSlot = res.getTimeSlot();
                if (timeSlot != null && !timeSlot.equals("")) {
                    String[] split = timeSlot.split(";");
                    res4.add(split[0]);
                    res4.add(split[1]);
                }
                expertConfigLists2Dto.setList(res4);
                expertConfigLists2Dto.setAddress(res.getAddress());
                expertConfigLists2Dto.setDay(res.getDay());
                expertConfigLists2Dto.setLimitsCount(res.getLimitsCount());

                //TODO 计算报名剩余人数
                Integer limitsCount = expertConfigLists2Dto.getLimitsCount();
                List<SciExpertReservation> listExpertReservation = expertReservationRepository.findByExpertOfflineId(res.getId());
                if (listExpertReservation != null) {
                    int last = limitsCount - listExpertReservation.size();
                    expertConfigLists2Dto.setResidueMan(last);
                } else {
                    expertConfigLists2Dto.setResidueMan(limitsCount);
                }
                result2.add(expertConfigLists2Dto);
            }
        }
        dto.setListOff(result2);

        String matype = dto.getMatype();
        if (matype != null && matype.contains(";")) {
            String[] array = matype.split(";");
            dto.setMatypes(array);
        } else {
            String[] array = {};
            dto.setMatypes(array);
        }
        String retype = dto.getRetype();
        if (retype != null && retype.contains(";")) {
            String[] array = retype.split(";");
            dto.setRetypes(array);
        } else {
            String[] array = {};
            dto.setRetypes(array);
        }
        String keyword = dto.getKeyword();
        if (keyword != null && keyword.contains(";")) {
            String[] array = keyword.split(";");
            dto.setKeywords(array);
        } else {
            String[] array = {};
            dto.setKeywords(array);
        }
        String orgArea = dto.getOrgArea();
        if (orgArea != null && orgArea.contains(";")) {
            String[] array = orgArea.split(";");
            dto.setOrgAreas(array);
        } else {
            String[] array = {};
            dto.setOrgAreas(array);
        }

        String companyArea = dto.getCompanyarea();
        if (companyArea != null && companyArea.contains(";")) {
            String[] array = companyArea.split(";");
            dto.setCompanyAreas(array);
        } else {
            String[] array = {};
            dto.setCompanyAreas(array);
        }

        List<ModelDemandAuditLog> modelDemandAuditLogs = modelDemandAuditLogRepository.findBySportdIdWithType(dto.getId(), model);
        dto.setListModelDemandAuditLog(modelDemandAuditLogs);

        //TODO 返回工作室信息
        List<SciStudio> listStudio = sciStudioRepository.findByMdId(dto.getId(), shtg);
        List<SciStudioDto> sciStudioDtos = sciStudioMapper.toDto(listStudio);
        if (sciStudioDtos != null && sciStudioDtos.size() > 0) {
            for (SciStudioDto dtomy : sciStudioDtos) {
                //TODO返回工作室信息
                String orgArea2 = dtomy.getOrgArea();
                if (orgArea2 != null && orgArea2.contains(";")) {
                    String[] array = orgArea2.split(";");
                    dtomy.setOrgAreas(array);
                } else {
                    String[] array = {};
                    dtomy.setOrgAreas(array);
                }

                String type = dtomy.getType();
                if (type != null && type.contains(";")) {
                    String[] array = type.split(";");
                    dtomy.setTypes(array);
                } else {
                    String[] array = {};
                    dtomy.setTypes(array);
                }

                List<SciStudioInfo> lists6 = sciStudioInfoRepository.findByStId(dtomy.getId());
                dtomy.setListSciStudioInfo(sciStudioInfoMapper.toDto(lists6));

                List<SciStudioImg> lists7 = sciStudioImgRepository.findByStId(dtomy.getId());
                List<SciStudioImgDto> sciStudioImgDtos = sciStudioImgMapper.toDto(lists7);
                List<String> imgs = new ArrayList<String>();
                if (sciStudioImgDtos != null && sciStudioImgDtos.size() > 0) {
                    for (SciStudioImgDto dto2 : sciStudioImgDtos) {
                        imgs.add(dto2.getPic());
                    }
                }
                dtomy.setListSciStudioImg(imgs);

                List<ModelDemandAuditLog> modelDemandAuditLogs2 = modelDemandAuditLogRepository.findBySportdIdWithType(dtomy.getId(), gzs);
                dtomy.setListModelDemandAuditLog(modelDemandAuditLogs2);

                List<SciCxResult> list5 = sciCxResultRepository.findByStudioId(dtomy.getId());
                if (list5 != null) {
                    List<SciCxResultDto> sciCxResultDtos = sciCxResultMapper.toDto(list5);
                    if (sciCxResultDtos != null && sciCxResultDtos.size() > 0) {
                        for (SciCxResultDto dto2 : sciCxResultDtos) {
                            String orgArea3 = dto2.getOrgArea();
                            if (orgArea3 != null && orgArea3.contains(";")) {
                                String[] array = orgArea3.split(";");
                                dto2.setOrgAreas(array);
                            } else {
                                String[] array = {};
                                dto2.setOrgAreas(array);
                            }
                            List<ModelDemandAuditLog> modelDemandAuditLogs3 = modelDemandAuditLogRepository.findBySportdIdWithType(dto2.getId(), cxcg);
                            dto2.setListModelDemandAuditLog(modelDemandAuditLogs3);
                            List<SciCxResultInfo> lists5 = sciCxResultInfoRepository.findByCxId(dto2.getId());
                            dto2.setListSciCxResultInfo(sciCxResultInfoMapper.toDto(lists5));
                        }
                    }
                    dtomy.setListCxcg(sciCxResultDtos);
                }
            }
        }
        dto.setListStudios(sciStudioDtos);


        //todo 被选中的需求列表
        List<SciPersonnelInfoMate> isSelect = sciPersonnelInfoMateRepository.findIsSelect(dto.getId());
        List<SciTechnologyDemandDto> listSelectDemands = new ArrayList<>();
        if (isSelect != null && isSelect.size() > 0) {
            for (SciPersonnelInfoMate sciPersonnelInfoMate : isSelect) {
                Integer tdId = sciPersonnelInfoMate.getTdId();
                Optional<SciTechnologyDemand> ops = sciTechnologyDemandRepository.findById(tdId);
                if (ops.isPresent()) {
                    SciTechnologyDemandDto sciTechnologyDemandDto = sciTechnologyDemandMapper.toDto(ops.get());


                    List<SciTechnologyDemandInfo> list6 = sciTechnologyDemandInfoRepository.findByTdId(sciTechnologyDemandDto.getId());
                    List<SciTechnologyDemandInfoDto> list7 = sciTechnologyDemandInfoMapper.toDto(list6);
                    if (list7 != null && list7.size() > 0) {
                        for (SciTechnologyDemandInfoDto info : list7) {
                            String maType = info.getMaType();
                            if (maType != null && maType.contains(";")) {
                                String[] array = maType.split(";");
                                info.setMaTypes(array);
                            } else {
                                String[] array = {};
                                info.setMaTypes(array);
                            }
                        }
                    }
                    sciTechnologyDemandDto.setListSdInfo(list7);

                    List<SciTechnologyDemandRecord> list9 = sciTechnologyDemandRecordRepository.findByTdId(sciTechnologyDemandDto.getId());
                    List<SciTechnologyDemandRecordDto> sciTechnologyDemandRecordDtos = sciTechnologyDemandRecordMapper.toDto(list9);
                    sciTechnologyDemandDto.setListRecord(sciTechnologyDemandRecordDtos);


                    String matype5 = sciTechnologyDemandDto.getMaType();
                    if (matype5 != null && matype5.contains(";")) {
                        String[] array = matype5.split(";");
                        sciTechnologyDemandDto.setMatypes(array);
                    } else {
                        String[] array = {};
                        sciTechnologyDemandDto.setMatypes(array);
                    }
                    String keyword5 = sciTechnologyDemandDto.getKeyword();
                    if (keyword5 != null && keyword5.contains(";")) {
                        String[] array = keyword5.split(";");
                        sciTechnologyDemandDto.setKeywords(array);
                    } else {
                        String[] array = {};
                        sciTechnologyDemandDto.setKeywords(array);
                    }
                    String orgArea5 = sciTechnologyDemandDto.getOrgArea();
                    if (orgArea5 != null && orgArea5.contains(";")) {
                        String[] array = orgArea5.split(";");
                        sciTechnologyDemandDto.setOrgAreas(array);
                    } else {
                        String[] array = {};
                        sciTechnologyDemandDto.setOrgAreas(array);
                    }
                    List<ModelDemandAuditLog> modelDemandAuditLogs5 = modelDemandAuditLogRepository.findBySportdIdWithType(sciTechnologyDemandDto.getId(), demand);
                    sciTechnologyDemandDto.setListModelDemandAuditLog(modelDemandAuditLogs5);

                    listSelectDemands.add(sciTechnologyDemandDto);
                }
            }
        }
        dto.setListSelectDemands(listSelectDemands);

        Integer qyId = dto.getQyId();
        if (qyId != null) {
            Optional<SciEnterprise> res = sciEnterpriseRepository.findById(qyId);
            if (res.isPresent()) {
                SciEnterprise sciEnterprise = res.get();
                dto.setQy(sciEnterpriseMapper.toDto(sciEnterprise));
            }
        }

        //TODO 看是否登录没登录都返回未收藏
        try {
            Long userId = SecurityUtils.getCurrentUserId();
            if (userId != null) {
                List<LoveModelRecord> res = loveModelRecordRepository.findByModelIdAndUserId(userId, dto.getId());
                if (res != null && res.size() > 0) {
                    dto.setIsLove(true);
                } else {
                    dto.setIsLove(false);
                }
            } else {
                dto.setIsLove(false);
            }
        } catch (Exception e) {
            dto.setIsLove(false);
        }
        //TODO 收藏的人数
        int loves = loveModelRecordRepository.findByModelId(dto.getId());
        dto.setLove(loves);


        List<Msg> listMsg = msgRepository.findNormalByGlIdWithAuditStatus(dto.getId(), "审核通过", "%劳模工匠%");
        if (listMsg != null && listMsg.size() > 0) {
            List<SmallMsgDto> myList = new ArrayList<SmallMsgDto>();
            for (Msg msg : listMsg) {
                SmallMsgDto smallMsgDto = new SmallMsgDto();
                smallMsgDto.setId(msg.getId());
                smallMsgDto.setGlId(msg.getGlId());
                smallMsgDto.setType(msg.getType());
                smallMsgDto.setContext(msg.getContext());
                smallMsgDto.setAuditStatus(msg.getAuditStatus());
                smallMsgDto.setUserId(msg.getUserId());
                smallMsgDto.setUpdateBy(msg.getUpdateBy());
                smallMsgDto.setCreateTime(msg.getCreateTime());
                smallMsgDto.setCreateBy(msg.getCreateBy());
                smallMsgDto.setUpdateTime(msg.getUpdateTime());
                Optional<UserSmall> res = userSmallRepository.findById(msg.getUserId());
                if (res.isPresent()) {
                    smallMsgDto.setUserSmall(res.get());
                }
                myList.add(smallMsgDto);
            }
            dto.setMsgDto(myList);
        }
        return dto;
    }


    public SciPersonnelInfoDto create(SciPersonnelInfoAddDto dto) {
        SciPersonnelInfo sciPersonnelInfo = new SciPersonnelInfo();
        if (dto.getQyId() != null) {
            Integer qyId = dto.getQyId();
            Optional<SciEnterprise> res = sciEnterpriseRepository.findById(qyId);
            if (res.isPresent()) {
                SciEnterprise sciEnterprise = res.get();
                if (sciEnterprise.getIsDelete() == 1) {
                    throw new BadRequestException("该企业已被删除,请重新选择");
                } else {
                    sciPersonnelInfo.setQyId(sciEnterprise.getId());
                }
            } else {
                throw new BadRequestException("未找到该企业,请重新选择");
            }
        } else {
            sciPersonnelInfo.setQyId(null);
        }
        sciPersonnelInfo.setDetails(dto.getDetails());
        sciPersonnelInfo.setZqxname(dto.getZqxname());
        sciPersonnelInfo.setSex(dto.getSex());
        sciPersonnelInfo.setDateBirth(dto.getDateBirth());
        sciPersonnelInfo.setIdcard(dto.getIdcard());
        sciPersonnelInfo.setEducation(dto.getEducation());
        sciPersonnelInfo.setEmployer(dto.getEmployer());
        sciPersonnelInfo.setJobTitle(dto.getJobTitle());
        sciPersonnelInfo.setUserId(SecurityUtils.getCurrentUserId());
        /*sciPersonnelInfo.setCompanyarea(dto.getCompanyarea());*/
        if (dto.getCompanyAreas() != null && dto.getCompanyAreas().length > 0) {
            String last = "";
            for (String a : dto.getCompanyAreas()) {
                last = last + a + ";";
            }
            sciPersonnelInfo.setCompanyarea(last);
        } else {
            sciPersonnelInfo.setCompanyarea(null);
        }
        sciPersonnelInfo.setWorkage(dto.getWorkage());
        sciPersonnelInfo.setHot(0);
        sciPersonnelInfo.setIsEdit(0);
        sciPersonnelInfo.setPreviousYearAchievements(dto.getPreviousYearAchievements());
        sciPersonnelInfo.setPreviousYearSkill(dto.getPreviousYearSkill());
        sciPersonnelInfo.setPhone(dto.getPhone());
        sciPersonnelInfo.setEmail(dto.getEmail());
        sciPersonnelInfo.setKeywordOther(dto.getKeywordOther());
        sciPersonnelInfo.setAddress(dto.getAddress());
        if (dto.getMatypes() != null && dto.getMatypes().length > 0) {
            String last = "";
            for (String a : dto.getMatypes()) {
                last = last + a + ";";
            }
            sciPersonnelInfo.setMatype(last);
        } else {
            sciPersonnelInfo.setMatype(null);
        }
        if (dto.getKeywords() != null && dto.getKeywords().length > 0) {
            String last = "";
            for (String a : dto.getKeywords()) {
                last = last + a + ";";
            }
            sciPersonnelInfo.setKeyword(last);
        } else {
            sciPersonnelInfo.setKeyword(null);
        }
        sciPersonnelInfo.setTechnology(dto.getTechnology());
        //sciPersonnelInfo.setRetype(dto.getRetype());
        if (dto.getRetypes() != null && dto.getRetypes().length > 0) {
            String last = "";
            for (String a : dto.getRetypes()) {
                last = last + a + ";";
            }
            sciPersonnelInfo.setRetype(last);
        } else {
            sciPersonnelInfo.setRetype(null);
        }
        sciPersonnelInfo.setPic(dto.getPic());
        sciPersonnelInfo.setIsDelete(0);
        sciPersonnelInfo.setAuditStatus(qxdsh);
        sciPersonnelInfo.setIsShow(0);
        sciPersonnelInfo.setSort(1);
        if (dto.getOrgAreas() != null && dto.getOrgAreas().length > 0) {
            String last = "";
            for (String a : dto.getOrgAreas()) {
                last = last + a + ";";
            }
            sciPersonnelInfo.setOrgArea(last);
        } else {
            sciPersonnelInfo.setOrgArea(orgAreaReturn());
        }
        //TODO 保存草稿
        if (dto.getAuditStatus() != null && dto.getAuditStatus().equals(caogao)) {//此状态为草稿
            if (dto.getZqxname() == null) {
                throw new BadRequestException("请输入劳模名称,再保存草稿");
            }
            if (dto.getOrgAreas() == null) {
                throw new BadRequestException("请选择地区组织,再保存草稿");
            }
            if (dto.getOrgAreas().length == 0) {
                throw new BadRequestException("请选择地区组织,再保存草稿");
            }
            /*if (dto.getQyId() == null){
                throw new BadRequestException("请选择企业,再保存草稿");
            }*/
            //设置
            sciPersonnelInfo.setAuditStatus(caogao);
            sciPersonnelInfo.setIsEdit(1);//允许编辑
        }
        //TODO 如果企业id不为null的话则查询该企业表里信息替换原来所传参数
        if (sciPersonnelInfo.getQyId() != null) {
            Optional<SciEnterprise> res = sciEnterpriseRepository.findById(sciPersonnelInfo.getQyId());
            if (!res.isPresent()) {
                throw new BadRequestException("未查询到该企业,请选择企业");
            }
            SciEnterprise sciEnterprise = res.get();
            //sciPersonnelInfo.setOrgArea(sciEnterprise.getOrgArea());
            sciPersonnelInfo.setCompanyarea(sciEnterprise.getCompanyArea());
        }

        SciPersonnelInfo save = sciPersonnelInfoRepository.save(sciPersonnelInfo);

        //根据id设置sort
        Optional<SciPersonnelInfo> result = sciPersonnelInfoRepository.findById(save.getId());
        if (result.isPresent()) {
            SciPersonnelInfo sciCxResult = result.get();
            sciCxResult.setSort(sciCxResult.getId());
            sciPersonnelInfoRepository.save(sciCxResult);
        }

        List<SciPersonnelInfoResultAddDto> listResult = dto.getListResult();
        List<SciPersonnelInfoWeAddDto> listWe = dto.getListWe();
        List<SciPersonnelInfoLessonAddDto> listLesson = dto.getListLesson();
        if (listResult != null && listResult.size() > 0) {
            for (SciPersonnelInfoResultAddDto res : listResult) {
                SciPersonnelInfoResult sciPersonnelInfoResult = new SciPersonnelInfoResult();
                sciPersonnelInfoResult.setAwardingunit(res.getAwardingunit());
                sciPersonnelInfoResult.setHonor(res.getHonor());
                sciPersonnelInfoResult.setWhattime(res.getWhattime());
                sciPersonnelInfoResult.setSpId(save.getId());
                sciPersonnelInfoResultRepository.save(sciPersonnelInfoResult);
            }
        }
        if (listWe != null && listWe.size() > 0) {
            for (SciPersonnelInfoWeAddDto res : listWe) {
                SciPersonnelInfoWe sciPersonnelInfoWe = new SciPersonnelInfoWe();
                sciPersonnelInfoWe.setPost(res.getPost());
                sciPersonnelInfoWe.setUnit(res.getUnit());
                sciPersonnelInfoWe.setSetime(res.getSetime());
                sciPersonnelInfoWe.setSpId(save.getId());
                sciPersonnelInfoWeRepository.save(sciPersonnelInfoWe);
            }
        }
        if (listLesson != null && listLesson.size() > 0) {
            for (SciPersonnelInfoLessonAddDto res : listLesson) {
                SciPersonnelInfoLesson sciPersonnelInfoLesson = new SciPersonnelInfoLesson();
                sciPersonnelInfoLesson.setLessonname(res.getLessonname());
                sciPersonnelInfoLesson.setValidity(res.getValidity());
                sciPersonnelInfoLesson.setTypeofwork(res.getTypeofwork());
                sciPersonnelInfoLesson.setSpId(save.getId());
                sciPersonnelInfoLessonRepository.save(sciPersonnelInfoLesson);
            }
        }
        SciPersonnelInfoDto sciPersonnelInfoDto = sciPersonnelInfoMapper.toDto(save);
        List<SciPersonnelInfoResult> results = sciPersonnelInfoResultRepository.findBySpId(save.getId());
        sciPersonnelInfoDto.setListResult(results);
        List<SciPersonnelInfoLesson> list2 = sciPersonnelInfoLessonRepository.findBySpId(save.getId());
        sciPersonnelInfoDto.setListLesson(list2);
        List<SciPersonnelInfoWe> list3 = sciPersonnelInfoWeRepository.findBySpId(save.getId());
        sciPersonnelInfoDto.setListWe(list3);
        String matype = sciPersonnelInfoDto.getMatype();
        if (matype != null && matype.contains(";")) {
            String[] array = matype.split(";");
            sciPersonnelInfoDto.setMatypes(array);
        } else {
            String[] array = {};
            sciPersonnelInfoDto.setMatypes(array);
        }
        String retype = sciPersonnelInfoDto.getRetype();
        if (retype != null && retype.contains(";")) {
            String[] array = retype.split(";");
            sciPersonnelInfoDto.setRetypes(array);
        } else {
            String[] array = {};
            sciPersonnelInfoDto.setRetypes(array);
        }
        Integer qyId = sciPersonnelInfoDto.getQyId();
        if (qyId != null) {
            Optional<SciEnterprise> res = sciEnterpriseRepository.findById(qyId);
            if (res.isPresent()) {
                SciEnterprise sciEnterprise = res.get();
                sciPersonnelInfoDto.setQy(sciEnterpriseMapper.toDto(sciEnterprise));
            }
        }


        //TODO 返回工作室信息
        List<SciStudio> listStudio = sciStudioRepository.findByMdId(sciPersonnelInfoDto.getId(), shtg);
        List<SciStudioDto> sciStudioDtos = sciStudioMapper.toDto(listStudio);
        if (sciStudioDtos != null && sciStudioDtos.size() > 0) {
            for (SciStudioDto dtomy : sciStudioDtos) {
                //TODO返回工作室信息
                String orgArea2 = dtomy.getOrgArea();
                if (orgArea2 != null && orgArea2.contains(";")) {
                    String[] array = orgArea2.split(";");
                    dtomy.setOrgAreas(array);
                } else {
                    String[] array = {};
                    dtomy.setOrgAreas(array);
                }

                String type = dtomy.getType();
                if (type != null && type.contains(";")) {
                    String[] array = type.split(";");
                    dtomy.setTypes(array);
                } else {
                    String[] array = {};
                    dtomy.setTypes(array);
                }

                List<SciStudioInfo> lists6 = sciStudioInfoRepository.findByStId(dtomy.getId());
                dtomy.setListSciStudioInfo(sciStudioInfoMapper.toDto(lists6));

                List<SciStudioImg> lists7 = sciStudioImgRepository.findByStId(dtomy.getId());
                List<SciStudioImgDto> sciStudioImgDtos = sciStudioImgMapper.toDto(lists7);
                List<String> imgs = new ArrayList<String>();
                if (sciStudioImgDtos != null && sciStudioImgDtos.size() > 0) {
                    for (SciStudioImgDto dto2 : sciStudioImgDtos) {
                        imgs.add(dto2.getPic());
                    }
                }
                dtomy.setListSciStudioImg(imgs);

                List<ModelDemandAuditLog> modelDemandAuditLogs2 = modelDemandAuditLogRepository.findBySportdIdWithType(dtomy.getId(), gzs);
                dtomy.setListModelDemandAuditLog(modelDemandAuditLogs2);

                List<SciCxResult> list5 = sciCxResultRepository.findByStudioId(dtomy.getId());
                if (list5 != null) {
                    List<SciCxResultDto> sciCxResultDtos = sciCxResultMapper.toDto(list5);
                    if (sciCxResultDtos != null && sciCxResultDtos.size() > 0) {
                        for (SciCxResultDto dto2 : sciCxResultDtos) {
                            String orgArea3 = dto2.getOrgArea();
                            if (orgArea3 != null && orgArea3.contains(";")) {
                                String[] array = orgArea3.split(";");
                                dto2.setOrgAreas(array);
                            } else {
                                String[] array = {};
                                dto2.setOrgAreas(array);
                            }
                            List<ModelDemandAuditLog> modelDemandAuditLogs3 = modelDemandAuditLogRepository.findBySportdIdWithType(dto2.getId(), cxcg);
                            dto2.setListModelDemandAuditLog(modelDemandAuditLogs3);
                            List<SciCxResultInfo> lists5 = sciCxResultInfoRepository.findByCxId(dto2.getId());
                            dto2.setListSciCxResultInfo(sciCxResultInfoMapper.toDto(lists5));
                        }
                    }
                    dtomy.setListCxcg(sciCxResultDtos);
                }
            }
        }
        sciPersonnelInfoDto.setListStudios(sciStudioDtos);
        return sciPersonnelInfoDto;
    }


    //新增草稿 直接保存 结束
    public SciPersonnelInfoDto addWithSaveSciDraft(SciPersonnelInfoAddDto dto) {
        if (dto.getZqxname() == null) {
            throw new BadRequestException("请输入劳模名称,再保存草稿");
        }
        if (dto.getOrgAreas() == null) {
            throw new BadRequestException("请选择地区组织,再保存草稿");
        }
        if (dto.getOrgAreas().length == 0) {
            throw new BadRequestException("请选择地区组织,再保存草稿");
        }
        SciPersonnelInfo sciPersonnelInfo = new SciPersonnelInfo();
        sciPersonnelInfo.setDetails(dto.getDetails());
        sciPersonnelInfo.setZqxname(dto.getZqxname());
        sciPersonnelInfo.setSex(dto.getSex());
        sciPersonnelInfo.setDateBirth(dto.getDateBirth());
        sciPersonnelInfo.setIdcard(dto.getIdcard());
        sciPersonnelInfo.setEducation(dto.getEducation());
        sciPersonnelInfo.setEmployer(dto.getEmployer());
        sciPersonnelInfo.setJobTitle(dto.getJobTitle());
        sciPersonnelInfo.setUserId(SecurityUtils.getCurrentUserId());
        /*sciPersonnelInfo.setCompanyarea(dto.getCompanyarea());*/
        if (dto.getCompanyAreas() != null && dto.getCompanyAreas().length > 0) {
            String last = "";
            for (String a : dto.getCompanyAreas()) {
                last = last + a + ";";
            }
            sciPersonnelInfo.setCompanyarea(last);
        } else {
            sciPersonnelInfo.setCompanyarea(null);
        }
        sciPersonnelInfo.setWorkage(dto.getWorkage());
        sciPersonnelInfo.setHot(0);
        sciPersonnelInfo.setIsEdit(1);
        sciPersonnelInfo.setPreviousYearAchievements(dto.getPreviousYearAchievements());
        sciPersonnelInfo.setPreviousYearSkill(dto.getPreviousYearSkill());
        sciPersonnelInfo.setPhone(dto.getPhone());
        sciPersonnelInfo.setEmail(dto.getEmail());
        sciPersonnelInfo.setKeywordOther(dto.getKeywordOther());
        sciPersonnelInfo.setAddress(dto.getAddress());
        if (dto.getMatypes() != null && dto.getMatypes().length > 0) {
            String last = "";
            for (String a : dto.getMatypes()) {
                last = last + a + ";";
            }
            sciPersonnelInfo.setMatype(last);
        } else {
            sciPersonnelInfo.setMatype(null);
        }
        if (dto.getKeywords() != null && dto.getKeywords().length > 0) {
            String last = "";
            for (String a : dto.getKeywords()) {
                last = last + a + ";";
            }
            sciPersonnelInfo.setKeyword(last);
        } else {
            sciPersonnelInfo.setKeyword(null);
        }
        sciPersonnelInfo.setTechnology(dto.getTechnology());
        //sciPersonnelInfo.setRetype(dto.getRetype());
        if (dto.getRetypes() != null && dto.getRetypes().length > 0) {
            String last = "";
            for (String a : dto.getRetypes()) {
                last = last + a + ";";
            }
            sciPersonnelInfo.setRetype(last);
        } else {
            sciPersonnelInfo.setRetype(null);
        }
        sciPersonnelInfo.setPic(dto.getPic());
        sciPersonnelInfo.setIsDelete(0);
        sciPersonnelInfo.setAuditStatus(caogao);
        sciPersonnelInfo.setIsShow(0);
        sciPersonnelInfo.setSort(1);
        if (dto.getOrgAreas() != null && dto.getOrgAreas().length > 0) {
            String last = "";
            for (String a : dto.getOrgAreas()) {
                last = last + a + ";";
            }
            sciPersonnelInfo.setOrgArea(last);
        } else {
            sciPersonnelInfo.setOrgArea(orgAreaReturn());
        }
        SciPersonnelInfo save = sciPersonnelInfoRepository.save(sciPersonnelInfo);

        //根据id设置sort
        Optional<SciPersonnelInfo> result = sciPersonnelInfoRepository.findById(save.getId());
        if (result.isPresent()) {
            SciPersonnelInfo sciCxResult = result.get();
            sciCxResult.setSort(sciCxResult.getId());
            sciPersonnelInfoRepository.save(sciCxResult);
        }

        List<SciPersonnelInfoResultAddDto> listResult = dto.getListResult();
        List<SciPersonnelInfoWeAddDto> listWe = dto.getListWe();
        List<SciPersonnelInfoLessonAddDto> listLesson = dto.getListLesson();
        if (listResult != null && listResult.size() > 0) {
            for (SciPersonnelInfoResultAddDto res : listResult) {
                SciPersonnelInfoResult sciPersonnelInfoResult = new SciPersonnelInfoResult();
                sciPersonnelInfoResult.setAwardingunit(res.getAwardingunit());
                sciPersonnelInfoResult.setHonor(res.getHonor());
                sciPersonnelInfoResult.setWhattime(res.getWhattime());
                sciPersonnelInfoResult.setSpId(save.getId());
                sciPersonnelInfoResultRepository.save(sciPersonnelInfoResult);
            }
        }
        if (listWe != null && listWe.size() > 0) {
            for (SciPersonnelInfoWeAddDto res : listWe) {
                SciPersonnelInfoWe sciPersonnelInfoWe = new SciPersonnelInfoWe();
                sciPersonnelInfoWe.setPost(res.getPost());
                sciPersonnelInfoWe.setUnit(res.getUnit());
                sciPersonnelInfoWe.setSetime(res.getSetime());
                sciPersonnelInfoWe.setSpId(save.getId());
                sciPersonnelInfoWeRepository.save(sciPersonnelInfoWe);
            }
        }
        if (listLesson != null && listLesson.size() > 0) {
            for (SciPersonnelInfoLessonAddDto res : listLesson) {
                SciPersonnelInfoLesson sciPersonnelInfoLesson = new SciPersonnelInfoLesson();
                sciPersonnelInfoLesson.setLessonname(res.getLessonname());
                sciPersonnelInfoLesson.setValidity(res.getValidity());
                sciPersonnelInfoLesson.setTypeofwork(res.getTypeofwork());
                sciPersonnelInfoLesson.setSpId(save.getId());
                sciPersonnelInfoLessonRepository.save(sciPersonnelInfoLesson);
            }
        }
        SciPersonnelInfoDto sciPersonnelInfoDto = sciPersonnelInfoMapper.toDto(save);
        List<SciPersonnelInfoResult> results = sciPersonnelInfoResultRepository.findBySpId(save.getId());
        sciPersonnelInfoDto.setListResult(results);
        List<SciPersonnelInfoLesson> list2 = sciPersonnelInfoLessonRepository.findBySpId(save.getId());
        sciPersonnelInfoDto.setListLesson(list2);
        List<SciPersonnelInfoWe> list3 = sciPersonnelInfoWeRepository.findBySpId(save.getId());
        sciPersonnelInfoDto.setListWe(list3);
        String matype = sciPersonnelInfoDto.getMatype();
        if (matype != null && matype.contains(";")) {
            String[] array = matype.split(";");
            sciPersonnelInfoDto.setMatypes(array);
        } else {
            String[] array = {};
            sciPersonnelInfoDto.setMatypes(array);
        }
        String retype = sciPersonnelInfoDto.getRetype();
        if (retype != null && retype.contains(";")) {
            String[] array = retype.split(";");
            sciPersonnelInfoDto.setRetypes(array);
        } else {
            String[] array = {};
            sciPersonnelInfoDto.setRetypes(array);
        }
        return sciPersonnelInfoDto;
    }


    public void update(SciPersonnelInfoEditDto dto) {
        SciPersonnelInfo sciPersonnelInfo = sciPersonnelInfoRepository.findById(dto.getId()).orElseGet(SciPersonnelInfo::new);
        //TODO 如果编辑时为驳回状态则 调整为区县待审核
        if (sciPersonnelInfo.getAuditStatus().equals(bh)) {
            sciPersonnelInfo.setAuditStatus(qxdsh);
        }
        ValidationUtil.isNull(sciPersonnelInfo.getId(), "SciPersonnelInfo", "id", dto.getId());
        sciPersonnelInfo.setDetails(dto.getDetails());
        sciPersonnelInfo.setZqxname(dto.getZqxname());
        sciPersonnelInfo.setSex(dto.getSex());
        if (dto.getQyId() != null) {
            Integer qyId = dto.getQyId();
            Optional<SciEnterprise> res = sciEnterpriseRepository.findById(qyId);
            if (res.isPresent()) {
                SciEnterprise sciEnterprise = res.get();
                if (sciEnterprise.getIsDelete() == 1) {
                    throw new BadRequestException("该企业已被删除,请重新选择");
                } else {
                    sciPersonnelInfo.setQyId(sciEnterprise.getId());
                }
            } else {
                throw new BadRequestException("未找到该企业,请重新选择");
            }
        } else {
            sciPersonnelInfo.setQyId(null);
        }
        sciPersonnelInfo.setDateBirth(dto.getDateBirth());
        sciPersonnelInfo.setIdcard(dto.getIdcard());
        sciPersonnelInfo.setEducation(dto.getEducation());
        sciPersonnelInfo.setEmployer(dto.getEmployer());
        sciPersonnelInfo.setJobTitle(dto.getJobTitle());
        //sciPersonnelInfo.setCompanyarea(dto.getCompanyarea());
        if (dto.getCompanyAreas() != null && dto.getCompanyAreas().length > 0) {
            String last = "";
            for (String a : dto.getCompanyAreas()) {
                last = last + a + ";";
            }
            sciPersonnelInfo.setCompanyarea(last);
        } else {
            sciPersonnelInfo.setCompanyarea(null);
        }
        sciPersonnelInfo.setWorkage(dto.getWorkage());
        //sciPersonnelInfo.setUserId(SecurityUtils.getCurrentUserId());
        sciPersonnelInfo.setPreviousYearAchievements(dto.getPreviousYearAchievements());
        sciPersonnelInfo.setPreviousYearSkill(dto.getPreviousYearSkill());
        sciPersonnelInfo.setPhone(dto.getPhone());
        sciPersonnelInfo.setEmail(dto.getEmail());
        sciPersonnelInfo.setKeywordOther(dto.getKeywordOther());
        sciPersonnelInfo.setAddress(dto.getAddress());
        if (dto.getMatypes() != null && dto.getMatypes().length > 0) {
            String last = "";
            for (String a : dto.getMatypes()) {
                last = last + a + ";";
            }
            sciPersonnelInfo.setMatype(last);
        } else {
            sciPersonnelInfo.setMatype(null);
        }
        sciPersonnelInfo.setTechnology(dto.getTechnology());
        //sciPersonnelInfo.setRetype(dto.getRetype());
        if (dto.getRetypes() != null && dto.getRetypes().length > 0) {
            String last = "";
            for (String a : dto.getRetypes()) {
                last = last + a + ";";
            }
            sciPersonnelInfo.setRetype(last);
        } else {
            sciPersonnelInfo.setRetype(null);
        }
        if (dto.getKeywords() != null && dto.getKeywords().length > 0) {
            String last = "";
            for (String a : dto.getKeywords()) {
                last = last + a + ";";
            }
            sciPersonnelInfo.setKeyword(last);
        } else {
            sciPersonnelInfo.setKeyword(null);
        }
        sciPersonnelInfo.setPic(dto.getPic());
        sciPersonnelInfo.setIsDelete(dto.getIsDelete());
        sciPersonnelInfo.setIsShow(dto.getIsShow());
        sciPersonnelInfo.setSort(dto.getSort());
        if (dto.getOrgAreas() != null && dto.getOrgAreas().length > 0) {
            String last = "";
            for (String a : dto.getOrgAreas()) {
                last = last + a + ";";
            }
            sciPersonnelInfo.setOrgArea(last);
        } else {
            sciPersonnelInfo.setOrgArea(orgAreaReturn());
        }
        //sciPersonnelInfo.setAuditStatus(dto.getAuditStatus());
        //sciPersonnelInfo.setSAuditStatus(dto.getSAuditStatus());

        if (dto.getAuditStatus().equals(caogao) && sciPersonnelInfo.getAuditStatus().equals(qxdsh)) {
            throw new BadRequestException("当前状态为区县待审核,无法保存为草稿");
        } else if (dto.getAuditStatus().equals(caogao) && sciPersonnelInfo.getAuditStatus().equals(sjdsh)) {
            throw new BadRequestException("当前状态为市级待审核,无法保存为草稿");
        } else if (dto.getAuditStatus().equals(caogao) && sciPersonnelInfo.getAuditStatus().equals(bh)) {
            throw new BadRequestException("当前状态为驳回,无法保存为草稿");
        } else if (dto.getAuditStatus().equals(caogao) && sciPersonnelInfo.getAuditStatus().equals(shtg)) {
            throw new BadRequestException("当前状态为审核通过,无法保存为草稿");
        } else {
            //TODO 保存草稿
            if (dto.getAuditStatus().equals(caogao)) {//此状态为草稿
                if (dto.getZqxname() == null) {
                    throw new BadRequestException("请输入劳模名称,再保存草稿");
                }
                if (dto.getOrgAreas() == null) {
                    throw new BadRequestException("请选择地区组织,再保存草稿");
                }
                if (dto.getOrgAreas().length == 0) {
                    throw new BadRequestException("请选择地区组织,再保存草稿");
                }
                /*if (dto.getQyId() == null){
                    throw new BadRequestException("请选择企业,再保存草稿");
                }*/
                //设置
                sciPersonnelInfo.setAuditStatus(caogao);
                sciPersonnelInfo.setIsEdit(1);//允许编辑
            }
        }

        //TODO 取消草稿
        if ((sciPersonnelInfo.getAuditStatus().equals(caogao) && dto.getAuditStatus() == null) || (sciPersonnelInfo.getAuditStatus().equals(caogao) && !dto.getAuditStatus().equals(caogao))) {
            //设置
            sciPersonnelInfo.setAuditStatus(qxdsh);
            sciPersonnelInfo.setIsEdit(0);
        }
        //TODO 如果企业id不为null的话则查询该企业表里信息替换原来所传参数
        if (sciPersonnelInfo.getQyId() != null) {
            Optional<SciEnterprise> res = sciEnterpriseRepository.findById(sciPersonnelInfo.getQyId());
            if (!res.isPresent()) {
                throw new BadRequestException("未查询到该企业,请选择企业");
            }
            SciEnterprise sciEnterprise = res.get();
            //sciPersonnelInfo.setOrgArea(sciEnterprise.getOrgArea());
            sciPersonnelInfo.setCompanyarea(sciEnterprise.getCompanyArea());
        }

        SciPersonnelInfo save = sciPersonnelInfoRepository.save(sciPersonnelInfo);
        List<SciPersonnelInfoResultAddDto> listResult = dto.getListResult();
        List<SciPersonnelInfoWeAddDto> listWe = dto.getListWe();
        List<SciPersonnelInfoLessonAddDto> listLesson = dto.getListLesson();
        if (listResult != null && listResult.size() > 0) {
            //List<SciPersonnelInfoResult> all = sciPersonnelInfoResultRepository.findAll();
            List<SciPersonnelInfoResult> all = sciPersonnelInfoResultRepository.findBySpId(save.getId());
            if (all != null && all.size() > 0) {
                for (SciPersonnelInfoResult result : all) {
                    sciPersonnelInfoResultRepository.deleteById(result.getId());
                }
            }
            for (SciPersonnelInfoResultAddDto res : listResult) {
                SciPersonnelInfoResult sciPersonnelInfoResult = new SciPersonnelInfoResult();
                sciPersonnelInfoResult.setAwardingunit(res.getAwardingunit());
                sciPersonnelInfoResult.setHonor(res.getHonor());
                sciPersonnelInfoResult.setWhattime(res.getWhattime());
                sciPersonnelInfoResult.setSpId(save.getId());
                sciPersonnelInfoResultRepository.save(sciPersonnelInfoResult);
            }
        }
        if (listWe != null && listWe.size() > 0) {
            //List<SciPersonnelInfoWe> all2 = sciPersonnelInfoWeRepository.findAll();
            List<SciPersonnelInfoWe> all2 = sciPersonnelInfoWeRepository.findBySpId(save.getId());
            if (all2 != null && all2.size() > 0) {
                for (SciPersonnelInfoWe result : all2) {
                    sciPersonnelInfoWeRepository.deleteById(result.getId());
                }
            }
            for (SciPersonnelInfoWeAddDto res : listWe) {
                SciPersonnelInfoWe sciPersonnelInfoWe = new SciPersonnelInfoWe();
                sciPersonnelInfoWe.setPost(res.getPost());
                sciPersonnelInfoWe.setUnit(res.getUnit());
                sciPersonnelInfoWe.setSetime(res.getSetime());
                sciPersonnelInfoWe.setSpId(save.getId());
                sciPersonnelInfoWeRepository.save(sciPersonnelInfoWe);
            }
        }
        if (listLesson != null && listLesson.size() > 0) {
            //List<SciPersonnelInfoLesson> all3 = sciPersonnelInfoLessonRepository.findAll();
            List<SciPersonnelInfoLesson> all3 = sciPersonnelInfoLessonRepository.findBySpId(save.getId());
            if (all3 != null && all3.size() > 0) {
                for (SciPersonnelInfoLesson result : all3) {
                    sciPersonnelInfoLessonRepository.deleteById(result.getId());
                }
            }
            for (SciPersonnelInfoLessonAddDto res : listLesson) {
                SciPersonnelInfoLesson sciPersonnelInfoLesson = new SciPersonnelInfoLesson();
                sciPersonnelInfoLesson.setLessonname(res.getLessonname());
                sciPersonnelInfoLesson.setValidity(res.getValidity());
                sciPersonnelInfoLesson.setTypeofwork(res.getTypeofwork());
                sciPersonnelInfoLesson.setSpId(save.getId());
                sciPersonnelInfoLessonRepository.save(sciPersonnelInfoLesson);
            }
        }
    }

    public void deleteAll(Integer[] ids) {
        for (Integer id : ids) {
            //假删除
            //sciPersonnelInfoRepository.deleteById(id);
            Optional<SciPersonnelInfo> res = sciPersonnelInfoRepository.findById(id);
            if (res.isPresent()) {
                SciPersonnelInfo sciPersonnelInfo = res.get();
                sciPersonnelInfo.setIsDelete(1);
                Timestamp currentTimestamp = new Timestamp(System.currentTimeMillis());
                sciPersonnelInfo.setDeleteTime(currentTimestamp);
                sciPersonnelInfoRepository.save(sciPersonnelInfo);
            }
        }
    }

    @Transactional(rollbackFor = Exception.class)
    public void auditSciPersonnelInfo(AuditSciPersonnelInfoDto dto) {
        Optional<SciPersonnelInfo> res = sciPersonnelInfoRepository.findById(dto.getId());
        if (!res.isPresent()) {
            throw new BadRequestException("未找到劳模工匠id");
        }
        String cAuditStatus = dto.getAuditStatus();
        if (cAuditStatus == null || cAuditStatus.equals("")) {
            throw new BadRequestException("缺少审核状态");
        }
        if (cAuditStatus.equals(caogao)) {
            throw new BadRequestException("状态为草稿状态,无法审核");
        }
        SciPersonnelInfo sciPersonnelInfo = res.get();
        //TODO 根据登录用户如果是市 的则审核市的字段    如果是区的则审核区的字段  admin暂不处理
        Long userId = SecurityUtils.getCurrentUserId();
        Optional<User> resUser = userRepository.findById(userId);
        if (!resUser.isPresent()) {
            throw new BadRequestException("未找到登录用户");
        }
        User user = resUser.get();
        String orgArea = user.getOrgArea();
        //TODO 如果orgArea里面有2个 ; 表示市级审核   3个; 表示区级审核  其他则不与通过
        if (orgArea == null || orgArea.equals("")) {
            throw new BadRequestException("缺少地区区域无法审核");
        }
        if (!orgArea.contains(";")) {
            throw new BadRequestException("地区区域不符合规范无法审核");
        }
        String[] results = orgArea.split(";");
        if (results.length == 1) {
            throw new BadRequestException("省级账号无法审核");
        } else if (results.length == 2) {
            if (cAuditStatus.equals(bh)) {//驳回
                if (!sciPersonnelInfo.getAuditStatus().equals(sjdsh)) {
                    throw new BadRequestException("区级审核未通过,无法操作");
                }
                //市级审核驳回 就变成区级待审核
                sciPersonnelInfo.setAuditStatus(qxdsh);
                sciPersonnelInfo.setIsEdit(1);//驳回设置为可编辑
                SciPersonnelInfo save = sciPersonnelInfoRepository.save(sciPersonnelInfo);

                ModelDemandAuditLog modelDemandAuditLog = new ModelDemandAuditLog();
                modelDemandAuditLog.setAdvice(dto.getAdvice());//市审核驳回建议
                modelDemandAuditLog.setType(model);
                modelDemandAuditLog.setStage(cityNoPass);
                modelDemandAuditLog.setSportdid(save.getId());
                modelDemandAuditLogRepository.save(modelDemandAuditLog);
            } else if (cAuditStatus.equals(shtg)) {
                if (!sciPersonnelInfo.getAuditStatus().equals(sjdsh)) {
                    throw new BadRequestException("区级审核未通过,无法操作");
                }
                //区级审核通过 市级审核通过则通过
                sciPersonnelInfo.setAuditStatus(shtg);
                //审核通过设为显示
                sciPersonnelInfo.setIsShow(1);
                if (sciPersonnelInfo.getIsEdit() == 1) {

                } else {
                    sciPersonnelInfo.setIsEdit(0); //打开了允许编辑就不管他 否住则设置为不可编辑
                }
                SciPersonnelInfo save = sciPersonnelInfoRepository.save(sciPersonnelInfo);

                ModelDemandAuditLog modelDemandAuditLog = new ModelDemandAuditLog();
                modelDemandAuditLog.setAdvice(dto.getAdvice());//市审核通过建议
                modelDemandAuditLog.setType(model);
                modelDemandAuditLog.setStage(cityPass);
                modelDemandAuditLog.setSportdid(save.getId());
                modelDemandAuditLogRepository.save(modelDemandAuditLog);
            } else {
                throw new BadRequestException("未符合规范的类型,无法审核");
            }
        } else if (results.length == 3) {
            if (cAuditStatus.equals(bh)) {//驳回
                //区级审核
                sciPersonnelInfo.setAuditStatus(cAuditStatus);
                sciPersonnelInfo.setIsEdit(1);//驳回设置为可编辑
                SciPersonnelInfo save = sciPersonnelInfoRepository.save(sciPersonnelInfo);

                ModelDemandAuditLog modelDemandAuditLog = new ModelDemandAuditLog();
                modelDemandAuditLog.setAdvice(dto.getAdvice());
                modelDemandAuditLog.setType(model);
                modelDemandAuditLog.setStage(quNoPass);//区审核驳回
                modelDemandAuditLog.setSportdid(save.getId());
                modelDemandAuditLogRepository.save(modelDemandAuditLog);
            } else if (cAuditStatus.equals(shtg)) {
                //区级审核通过 变为市级待审核
                sciPersonnelInfo.setAuditStatus(sjdsh);
                if (sciPersonnelInfo.getIsEdit() == 1) {

                } else {
                    sciPersonnelInfo.setIsEdit(0); //打开了允许编辑就不管他 否住则设置为不可编辑
                }
                SciPersonnelInfo save = sciPersonnelInfoRepository.save(sciPersonnelInfo);

                ModelDemandAuditLog modelDemandAuditLog = new ModelDemandAuditLog();
                modelDemandAuditLog.setAdvice(dto.getAdvice());//市审核通过建议
                modelDemandAuditLog.setType(model);
                modelDemandAuditLog.setStage(quPass);//区审核通过建议
                modelDemandAuditLog.setSportdid(save.getId());
                modelDemandAuditLogRepository.save(modelDemandAuditLog);
            } else {
                throw new BadRequestException("未符合规范的类型,无法审核");
            }
        } else {
            throw new BadRequestException("未符合的审级权限无法审核");
        }
    }

    public void download(List<SciPersonnelInfoDto> all, HttpServletResponse response) throws IOException {
        List<Map<String, Object>> list = new ArrayList<>();
        for (SciPersonnelInfoDto sciPersonnelInfo : all) {
            Map<String, Object> map = new LinkedHashMap<>();
            map.put("id", sciPersonnelInfo.getId());
            map.put("姓名", sciPersonnelInfo.getZqxname());
            map.put("性别", sciPersonnelInfo.getSex());
            map.put("出生年月", sciPersonnelInfo.getDateBirth());
            map.put("身份证号", sciPersonnelInfo.getIdcard());
            map.put("学历", sciPersonnelInfo.getEducation());
            map.put("工作单位", sciPersonnelInfo.getEmployer());
            map.put("现任职务", sciPersonnelInfo.getJobTitle());
            //map.put("企业所在区域", sciPersonnelInfo.getCompanyarea());
            map.put("本工种工龄", sciPersonnelInfo.getWorkage());
            map.put("职业资格及等级", sciPersonnelInfo.getPreviousYearAchievements());
            map.put("技术职称及等级", sciPersonnelInfo.getPreviousYearSkill());
            map.put("移动电话", sciPersonnelInfo.getPhone());
            map.put("电子邮件", sciPersonnelInfo.getEmail());
            map.put("通讯地址", sciPersonnelInfo.getAddress());
            map.put("本企业劳模、工匠情况劳模工匠人才类型", sciPersonnelInfo.getMatype());
            map.put("所需技术领域", sciPersonnelInfo.getTechnology());
            map.put("需求类别", sciPersonnelInfo.getRetype());
            map.put("简介", sciPersonnelInfo.getDetails());
            map.put("头像", sciPersonnelInfo.getPic());
            map.put("排序", sciPersonnelInfo.getSort());
            map.put("是否h5、小程序展示", sciPersonnelInfo.getIsShow());
            map.put("是否删除 默认否", sciPersonnelInfo.getIsDelete());
            //map.put("地区组织机构区分", sciPersonnelInfo.getOrgArea());
            map.put("审核状态", sciPersonnelInfo.getAuditStatus());
            map.put("热度", sciPersonnelInfo.getHot());
            map.put("是否允许编辑", sciPersonnelInfo.getIsEdit());
            map.put("关键字", sciPersonnelInfo.getKeyword());
            map.put("关键字其他", sciPersonnelInfo.getKeywordOther());
            String qyName = "";
            Integer qyId = sciPersonnelInfo.getQyId();
            if (qyId != null) {
                Optional<SciEnterprise> res = sciEnterpriseRepository.findById(qyId);
                if (res.isPresent()) {
                    SciEnterprise sciEnterprise = res.get();
                    qyName = sciEnterprise.getName();
                }
            }
            map.put("所属企业", qyName);
            String orgArea = sciPersonnelInfo.getOrgArea();
            if (orgArea != null) {
                if (orgArea.contains(";")) {
                    String[] split = orgArea.split(";");
                    String str = "";
                    for (String a : split) {
                        str = str + a + "/";
                    }
                    map.put("所属工会", str);
                } else {
                    map.put("所属工会", orgArea);
                }
            } else {
                map.put("所属工会", "");
            }
            String companyAreas = sciPersonnelInfo.getCompanyarea();
            if (companyAreas != null) {
                if (companyAreas.contains(";")) {
                    String[] split = companyAreas.split(";");
                    String str = "";
                    for (String a : split) {
                        str = str + a + "/";
                    }
                    map.put("企业所在区域", str);
                } else {
                    map.put("企业所在区域", companyAreas);
                }
            } else {
                map.put("企业所在区域", "");
            }
            list.add(map);
        }
        FileUtil.downloadExcel(list, response);
    }

    public List<DictDetailDto> getzqxCompanyArea() {
        DictQueryCriteria dictQueryCriteria = new DictQueryCriteria();
        dictQueryCriteria.setBlurry("zqx_company_area");
        List<DictDto> list = dictService.queryAll(dictQueryCriteria);
        if (list != null && list.size() == 1) {
            List<DictDetailDto> list1 = dictDetailService.getDictByDictId(list.get(0).getId());
            return list1;
        }
        return null;
    }

    public List<DictDetailDto> getZqxMaType() {
        DictQueryCriteria dictQueryCriteria = new DictQueryCriteria();
        dictQueryCriteria.setBlurry("zqx_ma_type");
        List<DictDto> list = dictService.queryAll(dictQueryCriteria);
        if (list != null && list.size() == 1) {
            List<DictDetailDto> list1 = dictDetailService.getDictByDictId(list.get(0).getId());
            return list1;
        }
        return null;
    }

    public List<DictDetailDto> getZqxTechnology() {
        DictQueryCriteria dictQueryCriteria = new DictQueryCriteria();
        dictQueryCriteria.setBlurry("zqx_technology");
        List<DictDto> list = dictService.queryAll(dictQueryCriteria);
        if (list != null && list.size() == 1) {
            List<DictDetailDto> list1 = dictDetailService.getDictByDictId(list.get(0).getId());
            return list1;
        }
        return null;
    }

    public List<DictDetailDto> getZqxReType() {
        DictQueryCriteria dictQueryCriteria = new DictQueryCriteria();
        dictQueryCriteria.setBlurry("zqx_re_type");
        List<DictDto> list = dictService.queryAll(dictQueryCriteria);
        if (list != null && list.size() == 1) {
            List<DictDetailDto> list1 = dictDetailService.getDictByDictId(list.get(0).getId());
            return list1;
        }
        return null;
    }

    public Boolean createAll(SciPersonnelInfoAddDto dto) {
        SciPersonnelInfo sciPersonnelInfo = new SciPersonnelInfo();
        if (dto.getQyId() != null) {
            Integer qyId = dto.getQyId();
            Optional<SciEnterprise> res = sciEnterpriseRepository.findById(qyId);
            if (res.isPresent()) {
                SciEnterprise sciEnterprise = res.get();
                if (sciEnterprise.getIsDelete() == 1) {
                    throw new BadRequestException("该企业已被删除,请重新选择");
                } else {
                    sciPersonnelInfo.setQyId(sciEnterprise.getId());
                }
            } else {
                throw new BadRequestException("未找到该企业,请重新选择");
            }
        } else {
            sciPersonnelInfo.setQyId(null);
        }
        sciPersonnelInfo.setDetails(dto.getDetails());
        sciPersonnelInfo.setZqxname(dto.getZqxname());
        sciPersonnelInfo.setSex(dto.getSex());
        sciPersonnelInfo.setDateBirth(dto.getDateBirth());
        sciPersonnelInfo.setIdcard(dto.getIdcard());
        sciPersonnelInfo.setEducation(dto.getEducation());
        sciPersonnelInfo.setEmployer(dto.getEmployer());
        sciPersonnelInfo.setJobTitle(dto.getJobTitle());
        sciPersonnelInfo.setIsEdit(0);
        sciPersonnelInfo.setUserId(SecurityUtils.getCurrentUserId());
        //sciPersonnelInfo.setCompanyarea(dto.getCompanyarea());
        if (dto.getCompanyAreas() != null && dto.getCompanyAreas().length > 0) {
            String last = "";
            for (String a : dto.getCompanyAreas()) {
                last = last + a + ";";
            }
            sciPersonnelInfo.setCompanyarea(last);
        } else {
            sciPersonnelInfo.setCompanyarea(null);
        }
        sciPersonnelInfo.setHot(0);
        sciPersonnelInfo.setWorkage(dto.getWorkage());
        sciPersonnelInfo.setPreviousYearAchievements(dto.getPreviousYearAchievements());
        sciPersonnelInfo.setPreviousYearSkill(dto.getPreviousYearSkill());
        sciPersonnelInfo.setPhone(dto.getPhone());
        sciPersonnelInfo.setEmail(dto.getEmail());
        sciPersonnelInfo.setKeywordOther(dto.getKeywordOther());
        sciPersonnelInfo.setAddress(dto.getAddress());
        if (dto.getMatypes() != null && dto.getMatypes().length > 0) {
            String last = "";
            for (String a : dto.getMatypes()) {
                last = last + a + ";";
            }
            sciPersonnelInfo.setMatype(last);
        } else {
            sciPersonnelInfo.setMatype(null);
        }
        sciPersonnelInfo.setTechnology(dto.getTechnology());
        //sciPersonnelInfo.setRetype(dto.getRetype());
        if (dto.getRetypes() != null && dto.getRetypes().length > 0) {
            String last = "";
            for (String a : dto.getRetypes()) {
                last = last + a + ";";
            }
            sciPersonnelInfo.setRetype(last);
        } else {
            sciPersonnelInfo.setRetype(null);
        }
        sciPersonnelInfo.setPic(dto.getPic());
        sciPersonnelInfo.setIsDelete(0);
        sciPersonnelInfo.setIsShow(0);
        sciPersonnelInfo.setSort(1);
        if (dto.getOrgAreas() != null && dto.getOrgAreas().length > 0) {
            String last = "";
            for (String a : dto.getOrgAreas()) {
                last = last + a + ";";
            }
            sciPersonnelInfo.setOrgArea(last);
        } else {
            sciPersonnelInfo.setOrgArea(orgAreaReturn());
        }
        if (dto.getKeywords() != null && dto.getKeywords().length > 0) {
            String last = "";
            for (String a : dto.getKeywords()) {
                last = last + a + ";";
            }
            sciPersonnelInfo.setKeyword(last);
        } else {
            sciPersonnelInfo.setKeyword(null);
        }
        sciPersonnelInfo.setAuditStatus(qxdsh);
        //TODO 如果企业id不为null的话则查询该企业表里信息替换原来所传参数
        if (sciPersonnelInfo.getQyId() != null) {
            Optional<SciEnterprise> res = sciEnterpriseRepository.findById(sciPersonnelInfo.getQyId());
            if (!res.isPresent()) {
                throw new BadRequestException("未查询到该企业,请选择企业");
            }
            SciEnterprise sciEnterprise = res.get();
            //sciPersonnelInfo.setOrgArea(sciEnterprise.getOrgArea());
            sciPersonnelInfo.setCompanyarea(sciEnterprise.getCompanyArea());
        }
        SciPersonnelInfo save = sciPersonnelInfoRepository.save(sciPersonnelInfo);
        //根据id设置sort
        Optional<SciPersonnelInfo> result = sciPersonnelInfoRepository.findById(save.getId());
        if (result.isPresent()) {
            SciPersonnelInfo sciCxResult = result.get();
            sciCxResult.setSort(sciCxResult.getId());
            sciPersonnelInfoRepository.save(sciCxResult);
        }
        List<SciPersonnelInfoResultAddDto> listResult = dto.getListResult();
        List<SciPersonnelInfoWeAddDto> listWe = dto.getListWe();
        List<SciPersonnelInfoLessonAddDto> listLesson = dto.getListLesson();
        if (listResult != null && listResult.size() > 0) {
            for (SciPersonnelInfoResultAddDto res : listResult) {
                SciPersonnelInfoResult sciPersonnelInfoResult = new SciPersonnelInfoResult();
                sciPersonnelInfoResult.setAwardingunit(res.getAwardingunit());
                sciPersonnelInfoResult.setHonor(res.getHonor());
                sciPersonnelInfoResult.setWhattime(res.getWhattime());
                sciPersonnelInfoResult.setSpId(save.getId());
                sciPersonnelInfoResultRepository.save(sciPersonnelInfoResult);
            }
        }
        if (listWe != null && listWe.size() > 0) {
            for (SciPersonnelInfoWeAddDto res : listWe) {
                SciPersonnelInfoWe sciPersonnelInfoWe = new SciPersonnelInfoWe();
                sciPersonnelInfoWe.setPost(res.getPost());
                sciPersonnelInfoWe.setUnit(res.getUnit());
                sciPersonnelInfoWe.setSetime(res.getSetime());
                sciPersonnelInfoWe.setSpId(save.getId());
                sciPersonnelInfoWeRepository.save(sciPersonnelInfoWe);
            }
        }
        if (listLesson != null && listLesson.size() > 0) {
            for (SciPersonnelInfoLessonAddDto res : listLesson) {
                SciPersonnelInfoLesson sciPersonnelInfoLesson = new SciPersonnelInfoLesson();
                sciPersonnelInfoLesson.setLessonname(res.getLessonname());
                sciPersonnelInfoLesson.setValidity(res.getValidity());
                sciPersonnelInfoLesson.setTypeofwork(res.getTypeofwork());
                sciPersonnelInfoLesson.setSpId(save.getId());
                sciPersonnelInfoLessonRepository.save(sciPersonnelInfoLesson);
            }
        }
        if (save != null) {
            return true;
        } else {
            return false;
        }
    }


    @Transactional(rollbackFor = Exception.class)
    public void isAllowEdit(AllowSciPersonnelInfoDto dto) {
        Optional<SciPersonnelInfo> res = sciPersonnelInfoRepository.findById(dto.getId());
        if (!res.isPresent()) {
            throw new BadRequestException("未找到劳模工匠id");
        }
        Integer isEdit = dto.getIsEdit();
        if (isEdit == null) {
            throw new BadRequestException("缺少参数");
        }
        if (isEdit != 0 && isEdit != 1) {
            throw new BadRequestException("参数错误无法操作");
        }
        SciPersonnelInfo sciPersonnelInfo = res.get();
        sciPersonnelInfo.setIsEdit(isEdit);
        sciPersonnelInfoRepository.save(sciPersonnelInfo);
    }

    public List<DictDetailDto> getKeywordsListType() {
        DictQueryCriteria dictQueryCriteria = new DictQueryCriteria();
        dictQueryCriteria.setBlurry("keywords_list");
        List<DictDto> list = dictService.queryAll(dictQueryCriteria);
        if (list != null && list.size() == 1) {
            List<DictDetailDto> list1 = dictDetailService.getDictByDictId(list.get(0).getId());
            return list1;
        }
        return null;
    }

    /*public String getZnToken() {
        String token = HttpUtils2.get(tokenUrl + "?userName=" + account + "&password=" + pwd);
        return token;
    }*/

    //获取当前时间前7天的时间
    public Date getUpSeven() {
        // 创建 Calendar 对象
        Calendar calendar = Calendar.getInstance();
        // 设置为当前时间
        calendar.setTimeInMillis(System.currentTimeMillis());
        // 将日期向前移动7天
        calendar.add(Calendar.DAY_OF_MONTH, -7);
        return calendar.getTime();
    }


    public String getModelListTOSendJson1() throws Exception {
        List<SciPersonnelInfo> listNormal = sciPersonnelInfoRepository.findNormalWithOutIsShowWithTime(shtg, getUpSeven(), new Date());
        List<Condition> list = new ArrayList<Condition>();
        if (listNormal != null && listNormal.size() > 0) {
            for (SciPersonnelInfo sciPersonnelInfo : listNormal) {
                Condition condition = new Condition();
                condition.setUid(sciPersonnelInfo.getId().toString());
                condition.setName(sciPersonnelInfo.getZqxname());
                condition.setSex(sciPersonnelInfo.getSex());
                condition.setBirthday(sciPersonnelInfo.getDateBirth());
                condition.setCard_num(sciPersonnelInfo.getIdcard());
                condition.setEducation(sciPersonnelInfo.getEducation());
                condition.setUnity(sciPersonnelInfo.getEmployer());
                condition.setDuties(sciPersonnelInfo.getJobTitle());
                condition.setArea(sciPersonnelInfo.getCompanyarea());
                condition.setJob_seniority(sciPersonnelInfo.getWorkage());
                condition.setJob_level(sciPersonnelInfo.getPreviousYearAchievements());
                condition.setTech_level(sciPersonnelInfo.getPreviousYearSkill());
                condition.setMobile(sciPersonnelInfo.getPhone());
                condition.setEmail(sciPersonnelInfo.getEmail());
                condition.setAddress(sciPersonnelInfo.getAddress());
                condition.setTalent_name(sciPersonnelInfo.getMatype());
                condition.setIndustry_type(sciPersonnelInfo.getTechnology());
                condition.setService_type(sciPersonnelInfo.getRetype());
                condition.setProfile(sciPersonnelInfo.getDetails());
                condition.setImage(sciPersonnelInfo.getPic());
                condition.setSort(sciPersonnelInfo.getSort().toString());
                condition.setArea_diff(sciPersonnelInfo.getOrgArea());
                condition.setHot(sciPersonnelInfo.getHot().toString());
                condition.setKeyword(sciPersonnelInfo.getKeyword());
                condition.setKeyword_other(sciPersonnelInfo.getKeywordOther());
                list.add(condition);
            }
        }
        DjDto dto = new DjDto();
        dto.setPath("/api.php?op=get_mst_lmgjdata");
        dto.setCondition(list);
        dto.setSystemCode("gyy");

        Gson gson = new Gson();
        String jsonString = gson.toJson(dto);
        return jsonString;
    }


    public String getModelZDTOSendJson1() throws Exception {
        //技术领域zqx_technology
        //服务能力zqx_re_type
        List<Condition2> list4 = new ArrayList<Condition2>();
        DictQueryCriteria dictQueryCriteria = new DictQueryCriteria();
        dictQueryCriteria.setBlurry("zqx_technology");
        List<DictDto> list = dictService.queryAll(dictQueryCriteria);
        if (list != null && list.size() == 1) {
            List<DictDetailDto> dictByDictIdWithDelete = dictDetailService.getDictByDictIdWithDelete(list.get(0).getId());
            List<DictDetailDto> list1 = dictDetailService.getDictByDictId(list.get(0).getId());
            if (list1 != null && list1.size() > 0) {
                for (DictDetailDto dictDetailDto : list1) {
                    Condition2 condition2 = new Condition2();
                    condition2.setType(1);//行业领域
                    condition2.setName(dictDetailDto.getLabel());
                    condition2.setCode(dictDetailDto.getValue());
                    condition2.setSort(dictDetailDto.getDictSort());
                    //判断此次字段发送是新增  还是编辑  还是删除
                    TechnologyReType byTypeLabel = technologyReTypeRepository.findByTypeLabel(1, dictDetailDto.getLabel());
                    if (byTypeLabel == null) {
                        //表示新增
                        condition2.setSync_status(1);
                        TechnologyReType technologyReType = new TechnologyReType();
                        technologyReType.setType(1);
                        technologyReType.setLabel(dictDetailDto.getLabel());
                        technologyReType.setValue(dictDetailDto.getValue());
                        technologyReType.setDictSort(dictDetailDto.getDictSort());
                        technologyReType.setIsdelete(dictDetailDto.getIsdelete());
                        technologyReTypeRepository.save(technologyReType);
                    } else {
                        //表示编辑
                        condition2.setSync_status(2);
                        byTypeLabel.setType(1);
                        byTypeLabel.setLabel(dictDetailDto.getLabel());
                        byTypeLabel.setValue(dictDetailDto.getValue());
                        byTypeLabel.setDictSort(dictDetailDto.getDictSort());
                        byTypeLabel.setIsdelete(dictDetailDto.getIsdelete());
                        technologyReTypeRepository.save(byTypeLabel);
                    }
                    list4.add(condition2);
                }

                if (dictByDictIdWithDelete.size() > list1.size()) {
                    //说明有假删除
                    for (DictDetailDto dto : dictByDictIdWithDelete) {
                        if (dto.getIsdelete() == 1) {
                            TechnologyReType byTypeLabel = technologyReTypeRepository.findByTypeLabel(1, dto.getLabel());
                            if (byTypeLabel != null) {
                                Integer isdelete = byTypeLabel.getIsdelete();
                                if (isdelete == 0) {
                                    //说明找到了设置为 删除状态
                                    //说明为刚删除  则需发送
                                    byTypeLabel.setIsdelete(1);
                                    byTypeLabel.setValue(dto.getValue());
                                    byTypeLabel.setDictSort(dto.getDictSort());
                                    technologyReTypeRepository.save(byTypeLabel);

                                    Condition2 condition2 = new Condition2();
                                    condition2.setType(1);//行业领域
                                    condition2.setName(dto.getLabel());
                                    condition2.setCode(dto.getValue());
                                    condition2.setSort(dto.getDictSort());
                                    condition2.setSync_status(3);
                                    list4.add(condition2);
                                }
                            }
                        }
                    }
                }
            }
        }
        DictQueryCriteria dictQueryCriteria2 = new DictQueryCriteria();
        dictQueryCriteria2.setBlurry("zqx_re_type");
        List<DictDto> list2 = dictService.queryAll(dictQueryCriteria2);
        if (list2 != null && list2.size() == 1) {
            List<DictDetailDto> dictByDictIdWithDelete2 = dictDetailService.getDictByDictIdWithDelete(list2.get(0).getId());
            List<DictDetailDto> listres = dictDetailService.getDictByDictId(list2.get(0).getId());
            if (listres != null && listres.size() > 0) {
                for (DictDetailDto dictDetailDto : listres) {
                    Condition2 condition2 = new Condition2();
                    condition2.setType(2);//服务能力
                    condition2.setName(dictDetailDto.getLabel());
                    condition2.setCode(dictDetailDto.getValue());
                    condition2.setSort(dictDetailDto.getDictSort());

                    //判断此次字段发送是新增  还是编辑  还是删除
                    TechnologyReType byTypeLabel = technologyReTypeRepository.findByTypeLabel(2, dictDetailDto.getLabel());
                    if (byTypeLabel == null) {
                        //表示新增
                        condition2.setSync_status(1);
                        TechnologyReType technologyReType = new TechnologyReType();
                        technologyReType.setType(2);
                        technologyReType.setLabel(dictDetailDto.getLabel());
                        technologyReType.setValue(dictDetailDto.getValue());
                        technologyReType.setDictSort(dictDetailDto.getDictSort());
                        technologyReType.setIsdelete(dictDetailDto.getIsdelete());
                        technologyReTypeRepository.save(technologyReType);
                    } else {
                        //表示编辑
                        condition2.setSync_status(2);
                        byTypeLabel.setType(2);
                        byTypeLabel.setLabel(dictDetailDto.getLabel());
                        byTypeLabel.setValue(dictDetailDto.getValue());
                        byTypeLabel.setDictSort(dictDetailDto.getDictSort());
                        byTypeLabel.setIsdelete(dictDetailDto.getIsdelete());
                        technologyReTypeRepository.save(byTypeLabel);
                    }
                    list4.add(condition2);
                }

                if (dictByDictIdWithDelete2.size() > listres.size()) {
                    //说明有假删除
                    for (DictDetailDto dto : dictByDictIdWithDelete2) {
                        if (dto.getIsdelete() == 1) {
                            TechnologyReType byTypeLabel = technologyReTypeRepository.findByTypeLabel(2, dto.getLabel());
                            if (byTypeLabel != null) {
                                Integer isdelete = byTypeLabel.getIsdelete();
                                if (isdelete == 0) {
                                    //说明找到了设置为 删除状态
                                    //说明为刚删除  则需发送
                                    byTypeLabel.setIsdelete(1);
                                    byTypeLabel.setValue(dto.getValue());
                                    byTypeLabel.setDictSort(dto.getDictSort());
                                    technologyReTypeRepository.save(byTypeLabel);

                                    Condition2 condition2 = new Condition2();
                                    condition2.setType(2);//服务能力
                                    condition2.setName(dto.getLabel());
                                    condition2.setCode(dto.getValue());
                                    condition2.setSort(dto.getDictSort());
                                    condition2.setSync_status(3);
                                    list4.add(condition2);
                                }
                            }
                        }
                    }
                }
            }
        }

        DjDto2 dto = new DjDto2();
        dto.setPath("/api.php?op=get_mst_fwjgsl");
        dto.setCondition(list4);
        dto.setSystemCode("gyy");

        Gson gson = new Gson();
        String jsonString = gson.toJson(dto);
        return jsonString;
    }

    public String getModelListTOSendJson() throws Exception {
        List<SciPersonnelInfo> listNormal = sciPersonnelInfoRepository.findNormalWithOutIsShowWithTime(shtg, getUpSeven(), new Date());
        List<Condition> list = new ArrayList<Condition>();
        if (listNormal != null && listNormal.size() > 0) {
            for (SciPersonnelInfo sciPersonnelInfo : listNormal) {
                Condition condition = new Condition();
                condition.setUid(sciPersonnelInfo.getId().toString());
                condition.setName(sciPersonnelInfo.getZqxname());
                condition.setSex(sciPersonnelInfo.getSex());
                condition.setBirthday(sciPersonnelInfo.getDateBirth());
                condition.setCard_num(sciPersonnelInfo.getIdcard());
                condition.setEducation(sciPersonnelInfo.getEducation());
                condition.setUnity(sciPersonnelInfo.getEmployer());
                condition.setDuties(sciPersonnelInfo.getJobTitle());
                condition.setArea(sciPersonnelInfo.getCompanyarea());
                condition.setJob_seniority(sciPersonnelInfo.getWorkage());
                condition.setJob_level(sciPersonnelInfo.getPreviousYearAchievements());
                condition.setTech_level(sciPersonnelInfo.getPreviousYearSkill());
                condition.setMobile(sciPersonnelInfo.getPhone());
                condition.setEmail(sciPersonnelInfo.getEmail());
                condition.setAddress(sciPersonnelInfo.getAddress());
                condition.setTalent_name(sciPersonnelInfo.getMatype());
                condition.setIndustry_type(sciPersonnelInfo.getTechnology());
                condition.setService_type(sciPersonnelInfo.getRetype());
                condition.setProfile(sciPersonnelInfo.getDetails());
                condition.setImage(sciPersonnelInfo.getPic());
                condition.setSort(sciPersonnelInfo.getSort().toString());
                condition.setArea_diff(sciPersonnelInfo.getOrgArea());
                condition.setHot(sciPersonnelInfo.getHot().toString());
                condition.setKeyword(sciPersonnelInfo.getKeyword());
                condition.setKeyword_other(sciPersonnelInfo.getKeywordOther());
                list.add(condition);
            }
        }
        DjDto dto = new DjDto();
        dto.setPath("/api.php?op=get_mst_lmgjdata");
        dto.setCondition(list);
        dto.setSystemCode("gyy");

        Gson gson = new Gson();
        String jsonString = gson.toJson(dto);
        String result = sendApiReq(jsonString);
        return result;
    }


    public String getModelZDTOSendJson() throws Exception {
        //技术领域zqx_technology
        //服务能力zqx_re_type
        List<Condition2> list4 = new ArrayList<Condition2>();
        DictQueryCriteria dictQueryCriteria = new DictQueryCriteria();
        dictQueryCriteria.setBlurry("zqx_technology");
        List<DictDto> list = dictService.queryAll(dictQueryCriteria);
        if (list != null && list.size() == 1) {
            List<DictDetailDto> dictByDictIdWithDelete = dictDetailService.getDictByDictIdWithDelete(list.get(0).getId());
            List<DictDetailDto> list1 = dictDetailService.getDictByDictId(list.get(0).getId());
            if (list1 != null && list1.size() > 0) {
                for (DictDetailDto dictDetailDto : list1) {
                    Condition2 condition2 = new Condition2();
                    condition2.setType(1);//行业领域
                    condition2.setName(dictDetailDto.getLabel());
                    condition2.setCode(dictDetailDto.getValue());
                    condition2.setSort(dictDetailDto.getDictSort());
                    //判断此次字段发送是新增  还是编辑  还是删除
                    TechnologyReType byTypeLabel = technologyReTypeRepository.findByTypeLabel(1, dictDetailDto.getLabel());
                    if (byTypeLabel == null) {
                        //表示新增
                        condition2.setSync_status(1);
                        TechnologyReType technologyReType = new TechnologyReType();
                        technologyReType.setType(1);
                        technologyReType.setLabel(dictDetailDto.getLabel());
                        technologyReType.setValue(dictDetailDto.getValue());
                        technologyReType.setDictSort(dictDetailDto.getDictSort());
                        technologyReType.setIsdelete(dictDetailDto.getIsdelete());
                        technologyReTypeRepository.save(technologyReType);
                    } else {
                        //表示编辑
                        condition2.setSync_status(2);
                        byTypeLabel.setType(1);
                        byTypeLabel.setLabel(dictDetailDto.getLabel());
                        byTypeLabel.setValue(dictDetailDto.getValue());
                        byTypeLabel.setDictSort(dictDetailDto.getDictSort());
                        byTypeLabel.setIsdelete(dictDetailDto.getIsdelete());
                        technologyReTypeRepository.save(byTypeLabel);
                    }
                    list4.add(condition2);
                }

                if (dictByDictIdWithDelete.size() > list1.size()) {
                    //说明有假删除
                    for (DictDetailDto dto : dictByDictIdWithDelete) {
                        if (dto.getIsdelete() == 1) {
                            TechnologyReType byTypeLabel = technologyReTypeRepository.findByTypeLabel(1, dto.getLabel());
                            if (byTypeLabel != null) {
                                Integer isdelete = byTypeLabel.getIsdelete();
                                if (isdelete == 0) {
                                    //说明找到了设置为 删除状态
                                    //说明为刚删除  则需发送
                                    byTypeLabel.setIsdelete(1);
                                    byTypeLabel.setValue(dto.getValue());
                                    byTypeLabel.setDictSort(dto.getDictSort());
                                    technologyReTypeRepository.save(byTypeLabel);

                                    Condition2 condition2 = new Condition2();
                                    condition2.setType(1);//行业领域
                                    condition2.setName(dto.getLabel());
                                    condition2.setCode(dto.getValue());
                                    condition2.setSort(dto.getDictSort());
                                    condition2.setSync_status(3);
                                    list4.add(condition2);
                                }
                            }
                        }
                    }
                }
            }
        }
        DictQueryCriteria dictQueryCriteria2 = new DictQueryCriteria();
        dictQueryCriteria2.setBlurry("zqx_re_type");
        List<DictDto> list2 = dictService.queryAll(dictQueryCriteria2);
        if (list2 != null && list2.size() == 1) {
            List<DictDetailDto> dictByDictIdWithDelete2 = dictDetailService.getDictByDictIdWithDelete(list2.get(0).getId());
            List<DictDetailDto> listres = dictDetailService.getDictByDictId(list2.get(0).getId());
            if (listres != null && listres.size() > 0) {
                for (DictDetailDto dictDetailDto : listres) {
                    Condition2 condition2 = new Condition2();
                    condition2.setType(2);//服务能力
                    condition2.setName(dictDetailDto.getLabel());
                    condition2.setCode(dictDetailDto.getValue());
                    condition2.setSort(dictDetailDto.getDictSort());

                    //判断此次字段发送是新增  还是编辑  还是删除
                    TechnologyReType byTypeLabel = technologyReTypeRepository.findByTypeLabel(2, dictDetailDto.getLabel());
                    if (byTypeLabel == null) {
                        //表示新增
                        condition2.setSync_status(1);
                        TechnologyReType technologyReType = new TechnologyReType();
                        technologyReType.setType(2);
                        technologyReType.setLabel(dictDetailDto.getLabel());
                        technologyReType.setValue(dictDetailDto.getValue());
                        technologyReType.setDictSort(dictDetailDto.getDictSort());
                        technologyReType.setIsdelete(dictDetailDto.getIsdelete());
                        technologyReTypeRepository.save(technologyReType);
                    } else {
                        //表示编辑
                        condition2.setSync_status(2);
                        byTypeLabel.setType(2);
                        byTypeLabel.setLabel(dictDetailDto.getLabel());
                        byTypeLabel.setValue(dictDetailDto.getValue());
                        byTypeLabel.setDictSort(dictDetailDto.getDictSort());
                        byTypeLabel.setIsdelete(dictDetailDto.getIsdelete());
                        technologyReTypeRepository.save(byTypeLabel);
                    }
                    list4.add(condition2);
                }

                if (dictByDictIdWithDelete2.size() > listres.size()) {
                    //说明有假删除
                    for (DictDetailDto dto : dictByDictIdWithDelete2) {
                        if (dto.getIsdelete() == 1) {
                            TechnologyReType byTypeLabel = technologyReTypeRepository.findByTypeLabel(2, dto.getLabel());
                            if (byTypeLabel != null) {
                                Integer isdelete = byTypeLabel.getIsdelete();
                                if (isdelete == 0) {
                                    //说明找到了设置为 删除状态
                                    //说明为刚删除  则需发送
                                    byTypeLabel.setIsdelete(1);
                                    byTypeLabel.setValue(dto.getValue());
                                    byTypeLabel.setDictSort(dto.getDictSort());
                                    technologyReTypeRepository.save(byTypeLabel);

                                    Condition2 condition2 = new Condition2();
                                    condition2.setType(2);//服务能力
                                    condition2.setName(dto.getLabel());
                                    condition2.setCode(dto.getValue());
                                    condition2.setSort(dto.getDictSort());
                                    condition2.setSync_status(3);
                                    list4.add(condition2);
                                }
                            }
                        }
                    }
                }
            }
        }

        DjDto2 dto = new DjDto2();
        dto.setPath("/api.php?op=get_mst_fwjgsl");
        dto.setCondition(list4);
        dto.setSystemCode("gyy");

        Gson gson = new Gson();
        String jsonString = gson.toJson(dto);
        String result = sendApiReq(jsonString);
        return result;
    }


    public String sendApiReq(String jsonString) throws Exception {
        String authRespStr = doGet(authUrl);
        JSONObject authResponse = JSONObject.parseObject(authRespStr);
        //加密的盐值，一般是通过接口获取到的randomKey
        JSONObject dataResponse = JSONObject.parseObject(authResponse.get("data").toString());
        ;
        String salt = (String) dataResponse.get("randomKey");
        String token = (String) dataResponse.get("token");
        logger.info("获取到的参数:salt【{}】:token【{}】", salt, token);
        //String jsonString =  "{\"path\":\"/api.php?op=get_mst_lmgjdata\",\"systemCode\":\"gyy\",\"condition\" :{\"page\":\"1\",\"limit\":\"1\"}}";
        //String jsonString =  "{\"path\":\"/api.php?op=get_mst_lmgjdata\",\"systemCode\":\"gyy\",\"condition\" :{\"uid\":\""+uid+"\",\"limit\":\"1\"}}";
        //System.out.println("请求参数为:" + jsonString);
        logger.info("请求参数为:jsonString【{}】", jsonString);
        String key = "_18eZ2frJX";
        jsonString = desEncrypt(jsonString, key);
        logger.info("请求加密后参数为:jsonString【{}】", jsonString);
        //System.out.println("请求加密后参数为:" + jsonString);
        //最后把base64加密后的数据和盐组合做md5加密
        String md5 = MD5Util.encrypt(jsonString + salt);
        //最终的传输对象为json字符串包含两个属性，object:base64加密的原始数据 sign: 组合加密的数据
        BaseTransferEntity baseTransferEntity = new BaseTransferEntity();
        baseTransferEntity.setObject(jsonString);
        baseTransferEntity.setSign(md5);
        String baseTransferEntityStr = JSON.toJSONString(baseTransferEntity);
        //logger.info("构造的参数：【{}】", baseTransferEntityStr);

        Map<String, String> headers = new HashMap<>();
        headers.put("Authorization-api", token);
        headers.put("Content-Type", "application/json");
        String s2 = HttpClientUtil.doPost(msgUrl, baseTransferEntityStr, headers);

        logger.info("返回结果未解密为:s2【{}】", s2);
        logger.info("返回结果为:result【{}】", DesTool.decryptString(s2, key));
        //System.out.println("返回结果为:"+ DesTool.decryptString(s2, key));
        return s2;
    }

    public static String desEncrypt(String message, String key) {
        //region 加密全量数据
        try {
            //logger.info("加密前：【{}】",message);
            //logger.info("加密密钥和解DesTool密密钥：【{}】",key);
            String encrypt = DesTool.encryptString(message, key);
            //logger.info("加密后：【{}】",encrypt);
            return encrypt;
        } catch (Exception e) {
            // logger.error("日志写入失败", e);
        }
        //endregion
        return null;
    }

    /**
     * get请求
     *
     * @return
     */
    public static String doGet(String url) {
        try {
            HttpClient client = new DefaultHttpClient();
            //发送get请求
            HttpGet request = new HttpGet(url);
            //log.info("请求url: "+url);
            HttpResponse response = client.execute(request);
            /**请求发送成功，并得到响应**/
            if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
                /**读取服务器返回过来的json字符串数据**/
                String strResult = EntityUtils.toString(response.getEntity());
                //log.info("请求返回结果: "+strResult);
                return strResult;
            }
        } catch (IOException e) {
            //log.error("请求返回错误!",e);
        }
        return null;
    }

    //单条单条的发
    public String getZnTestSendSingleTd() throws Exception {
        String end = "2024-04-29 09:00:00";
        String start = "2024-04-22 09:00:00";
        Date date1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(start);
        Date date2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(end);
        List<SciPersonnelInfo> listNormal = sciPersonnelInfoRepository.findNormalWithOutIsShowWithTime(shtg, date1, date2);
        //List<SciPersonnelInfo> listNormal = sciPersonnelInfoRepository.findNormalWithOutIsShowWithTime(shtg, getUpSeven(), new Date());
        List<Condition> list = new ArrayList<Condition>();
        if (listNormal != null && listNormal.size() > 0) {
            for (SciPersonnelInfo sciPersonnelInfo : listNormal) {
                if (sciPersonnelInfo.getZqxname().contains("于艳") ||
                        sciPersonnelInfo.getZqxname().contains("蔡雷鸣") ||
                        sciPersonnelInfo.getZqxname().contains("饶耿慧") ||
                        sciPersonnelInfo.getZqxname().contains("潘丽金") ||
                        sciPersonnelInfo.getZqxname().contains("林玉登") ||
                        sciPersonnelInfo.getZqxname().contains("陈锜") ||
                        sciPersonnelInfo.getZqxname().contains("陈海清") ||
                        sciPersonnelInfo.getZqxname().contains("吴恩权") ||
                        sciPersonnelInfo.getZqxname().contains("赵淑好") ||
                        sciPersonnelInfo.getZqxname().contains("周林") ||
                        sciPersonnelInfo.getZqxname().contains("杨国") ||
                        sciPersonnelInfo.getZqxname().contains("张冲") ||
                        sciPersonnelInfo.getZqxname().contains("毛永泉") ||
                        sciPersonnelInfo.getZqxname().contains("冯振波") ||
                        sciPersonnelInfo.getZqxname().contains("肖维军") ||
                        sciPersonnelInfo.getZqxname().contains("黄水儿") ||
                        sciPersonnelInfo.getZqxname().contains("饶绪黎") ||
                        sciPersonnelInfo.getZqxname().contains("郑楚飞") ||
                        sciPersonnelInfo.getZqxname().contains("陈建新") ||
                        sciPersonnelInfo.getZqxname().contains("甘景城") ||
                        sciPersonnelInfo.getZqxname().contains("王衍宇") ||
                        sciPersonnelInfo.getZqxname().contains("李景虎") ||
                        sciPersonnelInfo.getZqxname().contains("张如梅") ||
                        sciPersonnelInfo.getZqxname().contains("赵广愚") ||
                        sciPersonnelInfo.getZqxname().contains("王志华") ||
                        sciPersonnelInfo.getZqxname().contains("黄赞") ||
                        sciPersonnelInfo.getZqxname().contains("陈文学") ||
                        sciPersonnelInfo.getZqxname().contains("傅祥文") ||
                        sciPersonnelInfo.getZqxname().contains("赵武丽") ||
                        sciPersonnelInfo.getZqxname().contains("蒋维") ||
                        sciPersonnelInfo.getZqxname().contains("游雄峰") ||
                        sciPersonnelInfo.getZqxname().contains("何宝平") ||
                        sciPersonnelInfo.getZqxname().contains("罗丹") ||
                        sciPersonnelInfo.getZqxname().contains("师延财") ||
                        sciPersonnelInfo.getZqxname().contains("刘贤平") ||
                        sciPersonnelInfo.getZqxname().contains("王建民") ||
                        sciPersonnelInfo.getZqxname().contains("杨清海") ||
                        sciPersonnelInfo.getZqxname().contains("陈晞文") ||
                        sciPersonnelInfo.getZqxname().contains("吴建新") ||
                        sciPersonnelInfo.getZqxname().contains("杨康") ||
                        sciPersonnelInfo.getZqxname().contains("方振华") ||
                        sciPersonnelInfo.getZqxname().contains("吴欣") ||
                        sciPersonnelInfo.getZqxname().contains("危赛明") ||
                        sciPersonnelInfo.getZqxname().contains("吴章胜") ||
                        sciPersonnelInfo.getZqxname().contains("张凯铃") ||
                        sciPersonnelInfo.getZqxname().contains("何学智") ||
                        sciPersonnelInfo.getZqxname().contains("林鎏娟") ||
                        sciPersonnelInfo.getZqxname().contains("瞿汕") ||
                        sciPersonnelInfo.getZqxname().contains("黄颂") ||
                        sciPersonnelInfo.getZqxname().contains("林齐心") ||
                        sciPersonnelInfo.getZqxname().contains("池新庄") ||
                        sciPersonnelInfo.getZqxname().contains("尤兵") ||
                        sciPersonnelInfo.getZqxname().contains("葛岩") ||
                        sciPersonnelInfo.getZqxname().contains("王建华") ||
                        sciPersonnelInfo.getZqxname().contains("宫成军") ||
                        sciPersonnelInfo.getZqxname().contains("张辉") ||
                        sciPersonnelInfo.getZqxname().contains("王秋琳") ||
                        sciPersonnelInfo.getZqxname().contains("林春生") ||
                        sciPersonnelInfo.getZqxname().contains("于光龙") ||
                        sciPersonnelInfo.getZqxname().contains("郑其铣") ||
                        sciPersonnelInfo.getZqxname().contains("周华官") ||
                        sciPersonnelInfo.getZqxname().contains("朱赛容") ||
                        sciPersonnelInfo.getZqxname().contains("蔡基伟") ||
                        sciPersonnelInfo.getZqxname().contains("吴泽平") ||
                        sciPersonnelInfo.getZqxname().contains("王榆") ||
                        sciPersonnelInfo.getZqxname().contains("卢巍")
                ) {
                    continue;
                }
                Condition condition = new Condition();
                condition.setUid(sciPersonnelInfo.getId().toString());
                condition.setName(sciPersonnelInfo.getZqxname());
                condition.setSex(sciPersonnelInfo.getSex());
                condition.setBirthday(sciPersonnelInfo.getDateBirth());
                condition.setCard_num(sciPersonnelInfo.getIdcard());
                condition.setEducation(sciPersonnelInfo.getEducation());
                condition.setUnity(sciPersonnelInfo.getEmployer());
                condition.setDuties(sciPersonnelInfo.getJobTitle());
                condition.setArea(sciPersonnelInfo.getCompanyarea());
                condition.setJob_seniority(sciPersonnelInfo.getWorkage());
                condition.setJob_level(sciPersonnelInfo.getPreviousYearAchievements());
                condition.setTech_level(sciPersonnelInfo.getPreviousYearSkill());
                condition.setMobile(sciPersonnelInfo.getPhone());
                condition.setEmail(sciPersonnelInfo.getEmail());
                condition.setAddress(sciPersonnelInfo.getAddress());
                condition.setTalent_name(sciPersonnelInfo.getMatype());
                condition.setIndustry_type(sciPersonnelInfo.getTechnology());
                condition.setService_type(sciPersonnelInfo.getRetype());
                condition.setProfile(sciPersonnelInfo.getDetails());
                condition.setImage(sciPersonnelInfo.getPic());
                condition.setSort(sciPersonnelInfo.getSort().toString());
                condition.setArea_diff(sciPersonnelInfo.getOrgArea());
                condition.setHot(sciPersonnelInfo.getHot().toString());
                condition.setKeyword(sciPersonnelInfo.getKeyword());
                condition.setKeyword_other(sciPersonnelInfo.getKeywordOther());
                list.add(condition);
            }
        }


        if (list != null && list.size() > 0) {
            for (Condition condition : list) {
                DjDtoSingle dto = new DjDtoSingle();
                dto.setPath("/api.php?op=get_mst_lmgjdata");
                dto.setCondition(condition);
                dto.setSystemCode("gyy");
                Gson gson = new Gson();
                String jsonString = gson.toJson(dto);
                sendApiReq(jsonString);
            }
        }
        return "success";
    }


    //单条单条的发
    public String getZnTest2SendSingle() throws Exception {
        //技术领域zqx_technology
        //服务能力zqx_re_type
        List<Condition2> list4 = new ArrayList<Condition2>();
        DictQueryCriteria dictQueryCriteria = new DictQueryCriteria();
        dictQueryCriteria.setBlurry("zqx_technology");
        List<DictDto> list = dictService.queryAll(dictQueryCriteria);
        if (list != null && list.size() == 1) {
            List<DictDetailDto> dictByDictIdWithDelete = dictDetailService.getDictByDictIdWithDelete(list.get(0).getId());
            List<DictDetailDto> list1 = dictDetailService.getDictByDictId(list.get(0).getId());
            if (list1 != null && list1.size() > 0) {
                for (DictDetailDto dictDetailDto : list1) {
                    Condition2 condition2 = new Condition2();
                    condition2.setType(1);//行业领域
                    condition2.setName(dictDetailDto.getLabel());
                    condition2.setCode(dictDetailDto.getValue());
                    condition2.setSort(dictDetailDto.getDictSort());
                    //判断此次字段发送是新增  还是编辑  还是删除
                    TechnologyReType byTypeLabel = technologyReTypeRepository.findByTypeLabel(1, dictDetailDto.getLabel());
                    if (byTypeLabel == null) {
                        //表示新增
                        condition2.setSync_status(1);
                        TechnologyReType technologyReType = new TechnologyReType();
                        technologyReType.setType(1);
                        technologyReType.setLabel(dictDetailDto.getLabel());
                        technologyReType.setValue(dictDetailDto.getValue());
                        technologyReType.setDictSort(dictDetailDto.getDictSort());
                        technologyReType.setIsdelete(dictDetailDto.getIsdelete());
                        technologyReTypeRepository.save(technologyReType);
                    } else {
                        //表示编辑
                        condition2.setSync_status(2);
                        byTypeLabel.setType(1);
                        byTypeLabel.setLabel(dictDetailDto.getLabel());
                        byTypeLabel.setValue(dictDetailDto.getValue());
                        byTypeLabel.setDictSort(dictDetailDto.getDictSort());
                        byTypeLabel.setIsdelete(dictDetailDto.getIsdelete());
                        technologyReTypeRepository.save(byTypeLabel);
                    }
                    list4.add(condition2);
                }

                if (dictByDictIdWithDelete.size() > list1.size()) {
                    //说明有假删除
                    for (DictDetailDto dto : dictByDictIdWithDelete) {
                        if (dto.getIsdelete() == 1) {
                            TechnologyReType byTypeLabel = technologyReTypeRepository.findByTypeLabel(1, dto.getLabel());
                            if (byTypeLabel != null) {
                                Integer isdelete = byTypeLabel.getIsdelete();
                                if (isdelete == 0) {
                                    //说明找到了设置为 删除状态
                                    //说明为刚删除  则需发送
                                    byTypeLabel.setIsdelete(1);
                                    byTypeLabel.setValue(dto.getValue());
                                    byTypeLabel.setDictSort(dto.getDictSort());
                                    technologyReTypeRepository.save(byTypeLabel);

                                    Condition2 condition2 = new Condition2();
                                    condition2.setType(1);//行业领域
                                    condition2.setName(dto.getLabel());
                                    condition2.setCode(dto.getValue());
                                    condition2.setSort(dto.getDictSort());
                                    condition2.setSync_status(3);
                                    list4.add(condition2);
                                }
                            }
                        }
                    }
                }
            }
        }
        DictQueryCriteria dictQueryCriteria2 = new DictQueryCriteria();
        dictQueryCriteria2.setBlurry("zqx_re_type");
        List<DictDto> list2 = dictService.queryAll(dictQueryCriteria2);
        if (list2 != null && list2.size() == 1) {
            List<DictDetailDto> dictByDictIdWithDelete2 = dictDetailService.getDictByDictIdWithDelete(list2.get(0).getId());
            List<DictDetailDto> listres = dictDetailService.getDictByDictId(list2.get(0).getId());
            if (listres != null && listres.size() > 0) {
                for (DictDetailDto dictDetailDto : listres) {
                    Condition2 condition2 = new Condition2();
                    condition2.setType(2);//服务能力
                    condition2.setName(dictDetailDto.getLabel());
                    condition2.setCode(dictDetailDto.getValue());
                    condition2.setSort(dictDetailDto.getDictSort());

                    //判断此次字段发送是新增  还是编辑  还是删除
                    TechnologyReType byTypeLabel = technologyReTypeRepository.findByTypeLabel(2, dictDetailDto.getLabel());
                    if (byTypeLabel == null) {
                        //表示新增
                        condition2.setSync_status(1);
                        TechnologyReType technologyReType = new TechnologyReType();
                        technologyReType.setType(2);
                        technologyReType.setLabel(dictDetailDto.getLabel());
                        technologyReType.setValue(dictDetailDto.getValue());
                        technologyReType.setDictSort(dictDetailDto.getDictSort());
                        technologyReType.setIsdelete(dictDetailDto.getIsdelete());
                        technologyReTypeRepository.save(technologyReType);
                    } else {
                        //表示编辑
                        condition2.setSync_status(2);
                        byTypeLabel.setType(2);
                        byTypeLabel.setLabel(dictDetailDto.getLabel());
                        byTypeLabel.setValue(dictDetailDto.getValue());
                        byTypeLabel.setDictSort(dictDetailDto.getDictSort());
                        byTypeLabel.setIsdelete(dictDetailDto.getIsdelete());
                        technologyReTypeRepository.save(byTypeLabel);
                    }
                    list4.add(condition2);
                }

                if (dictByDictIdWithDelete2.size() > listres.size()) {
                    //说明有假删除
                    for (DictDetailDto dto : dictByDictIdWithDelete2) {
                        if (dto.getIsdelete() == 1) {
                            TechnologyReType byTypeLabel = technologyReTypeRepository.findByTypeLabel(2, dto.getLabel());
                            if (byTypeLabel != null) {
                                Integer isdelete = byTypeLabel.getIsdelete();
                                if (isdelete == 0) {
                                    //说明找到了设置为 删除状态
                                    //说明为刚删除  则需发送
                                    byTypeLabel.setIsdelete(1);
                                    byTypeLabel.setValue(dto.getValue());
                                    byTypeLabel.setDictSort(dto.getDictSort());
                                    technologyReTypeRepository.save(byTypeLabel);

                                    Condition2 condition2 = new Condition2();
                                    condition2.setType(2);//服务能力
                                    condition2.setName(dto.getLabel());
                                    condition2.setCode(dto.getValue());
                                    condition2.setSort(dto.getDictSort());
                                    condition2.setSync_status(3);
                                    list4.add(condition2);
                                }
                            }
                        }
                    }
                }
            }
        }


        if (list4 != null && list4.size() > 0) {
            for (Condition2 condition2 : list4) {
                DjDto2Single dto = new DjDto2Single();
                dto.setPath("/api.php?op=get_mst_fwjgsl");
                dto.setCondition(condition2);
                dto.setSystemCode("gyy");

                Gson gson = new Gson();
                String jsonString = gson.toJson(dto);
                sendApiReq(jsonString);
            }
        }
        return "success";
    }

    //单条单条的发
    public String getZnTestSendSingle() throws Exception {
        List<SciPersonnelInfo> listNormal = sciPersonnelInfoRepository.findNormalWithOutIsShowWithTime(shtg, getUpSeven(), new Date());
        List<Condition> list = new ArrayList<Condition>();
        if (listNormal != null && listNormal.size() > 0) {
            for (SciPersonnelInfo sciPersonnelInfo : listNormal) {
                Condition condition = new Condition();
                condition.setUid(sciPersonnelInfo.getId().toString());
                condition.setName(sciPersonnelInfo.getZqxname());
                condition.setSex(sciPersonnelInfo.getSex());
                condition.setBirthday(sciPersonnelInfo.getDateBirth());
                condition.setCard_num(sciPersonnelInfo.getIdcard());
                condition.setEducation(sciPersonnelInfo.getEducation());
                condition.setUnity(sciPersonnelInfo.getEmployer());
                condition.setDuties(sciPersonnelInfo.getJobTitle());
                condition.setArea(sciPersonnelInfo.getCompanyarea());
                condition.setJob_seniority(sciPersonnelInfo.getWorkage());
                condition.setJob_level(sciPersonnelInfo.getPreviousYearAchievements());
                condition.setTech_level(sciPersonnelInfo.getPreviousYearSkill());
                condition.setMobile(sciPersonnelInfo.getPhone());
                condition.setEmail(sciPersonnelInfo.getEmail());
                condition.setAddress(sciPersonnelInfo.getAddress());
                condition.setTalent_name(sciPersonnelInfo.getMatype());
                condition.setIndustry_type(sciPersonnelInfo.getTechnology());
                condition.setService_type(sciPersonnelInfo.getRetype());
                condition.setProfile(sciPersonnelInfo.getDetails());
                condition.setImage(sciPersonnelInfo.getPic());
                condition.setSort(sciPersonnelInfo.getSort().toString());
                condition.setArea_diff(sciPersonnelInfo.getOrgArea());
                condition.setHot(sciPersonnelInfo.getHot().toString());
                condition.setKeyword(sciPersonnelInfo.getKeyword());
                condition.setKeyword_other(sciPersonnelInfo.getKeywordOther());
                list.add(condition);
            }
        }


        if (list != null && list.size() > 0) {
            for (Condition condition : list) {
                DjDtoSingle dto = new DjDtoSingle();
                dto.setPath("/api.php?op=get_mst_lmgjdata");
                dto.setCondition(condition);
                dto.setSystemCode("gyy");
                Gson gson = new Gson();
                String jsonString = gson.toJson(dto);
                sendApiReq(jsonString);
            }
        }
        return "success";
    }


    //单条单条的发所有劳模记录
    public String allgetZnTestSendSingle() throws Exception {
        List<SciPersonnelInfo> listNormal = sciPersonnelInfoRepository.findNormalWithOutIsShowWithOutAllTime(shtg);
        List<Condition> list = new ArrayList<Condition>();
        if (listNormal != null && listNormal.size() > 0) {
            for (SciPersonnelInfo sciPersonnelInfo : listNormal) {
                Condition condition = new Condition();
                condition.setUid(sciPersonnelInfo.getId().toString());
                condition.setName(sciPersonnelInfo.getZqxname());
                condition.setSex(sciPersonnelInfo.getSex());
                condition.setBirthday(sciPersonnelInfo.getDateBirth());
                condition.setCard_num(sciPersonnelInfo.getIdcard());
                condition.setEducation(sciPersonnelInfo.getEducation());
                condition.setUnity(sciPersonnelInfo.getEmployer());
                condition.setDuties(sciPersonnelInfo.getJobTitle());
                condition.setArea(sciPersonnelInfo.getCompanyarea());
                condition.setJob_seniority(sciPersonnelInfo.getWorkage());
                condition.setJob_level(sciPersonnelInfo.getPreviousYearAchievements());
                condition.setTech_level(sciPersonnelInfo.getPreviousYearSkill());
                condition.setMobile(sciPersonnelInfo.getPhone());
                condition.setEmail(sciPersonnelInfo.getEmail());
                condition.setAddress(sciPersonnelInfo.getAddress());
                condition.setTalent_name(sciPersonnelInfo.getMatype());
                condition.setIndustry_type(sciPersonnelInfo.getTechnology());
                condition.setService_type(sciPersonnelInfo.getRetype());
                condition.setProfile(sciPersonnelInfo.getDetails());
                condition.setImage(sciPersonnelInfo.getPic());
                condition.setSort(sciPersonnelInfo.getSort().toString());
                condition.setArea_diff(sciPersonnelInfo.getOrgArea());
                condition.setHot(sciPersonnelInfo.getHot().toString());
                condition.setKeyword(sciPersonnelInfo.getKeyword());
                condition.setKeyword_other(sciPersonnelInfo.getKeywordOther());
                list.add(condition);
            }
        }


        if (list != null && list.size() > 0) {
            for (Condition condition : list) {
                DjDtoSingle dto = new DjDtoSingle();
                dto.setPath("/api.php?op=get_mst_lmgjdata");
                dto.setCondition(condition);
                dto.setSystemCode("gyy");
                Gson gson = new Gson();
                String jsonString = gson.toJson(dto);
                sendApiReq(jsonString);
            }
        }
        return "success";
    }


    //单条单条的发劳模技术领域等
    public String sendDjModelRetype() throws Exception {
        //技术领域zqx_technology
        //服务能力zqx_re_type
        List<Condition2> list4 = new ArrayList<Condition2>();
        DictQueryCriteria dictQueryCriteria = new DictQueryCriteria();
        dictQueryCriteria.setBlurry("zqx_technology");
        List<DictDto> list = dictService.queryAll(dictQueryCriteria);
        if (list != null && list.size() == 1) {
            List<DictDetailDto> dictByDictIdWithDelete = dictDetailService.getDictByDictIdWithDelete(list.get(0).getId());
            List<DictDetailDto> list1 = dictDetailService.getDictByDictId(list.get(0).getId());
            if (list1 != null && list1.size() > 0) {
                for (DictDetailDto dictDetailDto : list1) {
                    Condition2 condition2 = new Condition2();
                    condition2.setType(1);//行业领域
                    condition2.setName(dictDetailDto.getLabel());
                    condition2.setCode(dictDetailDto.getValue());
                    condition2.setSort(dictDetailDto.getDictSort());
                    //判断此次字段发送是新增  还是编辑  还是删除
                    TechnologyReType byTypeLabel = technologyReTypeRepository.findByTypeLabel(1, dictDetailDto.getLabel());
                    if (byTypeLabel == null) {
                        //表示新增
                        condition2.setSync_status(1);
                        TechnologyReType technologyReType = new TechnologyReType();
                        technologyReType.setType(1);
                        technologyReType.setLabel(dictDetailDto.getLabel());
                        technologyReType.setValue(dictDetailDto.getValue());
                        technologyReType.setDictSort(dictDetailDto.getDictSort());
                        technologyReType.setIsdelete(dictDetailDto.getIsdelete());
                        technologyReTypeRepository.save(technologyReType);
                    } else {
                        //表示编辑
                        condition2.setSync_status(2);
                        byTypeLabel.setType(1);
                        byTypeLabel.setLabel(dictDetailDto.getLabel());
                        byTypeLabel.setValue(dictDetailDto.getValue());
                        byTypeLabel.setDictSort(dictDetailDto.getDictSort());
                        byTypeLabel.setIsdelete(dictDetailDto.getIsdelete());
                        technologyReTypeRepository.save(byTypeLabel);
                    }
                    list4.add(condition2);
                }

                if (dictByDictIdWithDelete.size() > list1.size()) {
                    //说明有假删除
                    for (DictDetailDto dto : dictByDictIdWithDelete) {
                        if (dto.getIsdelete() == 1) {
                            TechnologyReType byTypeLabel = technologyReTypeRepository.findByTypeLabel(1, dto.getLabel());
                            if (byTypeLabel != null) {
                                Integer isdelete = byTypeLabel.getIsdelete();
                                if (isdelete == 0) {
                                    //说明找到了设置为 删除状态
                                    //说明为刚删除  则需发送
                                    byTypeLabel.setIsdelete(1);
                                    byTypeLabel.setValue(dto.getValue());
                                    byTypeLabel.setDictSort(dto.getDictSort());
                                    technologyReTypeRepository.save(byTypeLabel);

                                    Condition2 condition2 = new Condition2();
                                    condition2.setType(1);//行业领域
                                    condition2.setName(dto.getLabel());
                                    condition2.setCode(dto.getValue());
                                    condition2.setSort(dto.getDictSort());
                                    condition2.setSync_status(3);
                                    list4.add(condition2);
                                }
                            }
                        }
                    }
                }
            }
        }
        DictQueryCriteria dictQueryCriteria2 = new DictQueryCriteria();
        dictQueryCriteria2.setBlurry("zqx_re_type");
        List<DictDto> list2 = dictService.queryAll(dictQueryCriteria2);
        if (list2 != null && list2.size() == 1) {
            List<DictDetailDto> dictByDictIdWithDelete2 = dictDetailService.getDictByDictIdWithDelete(list2.get(0).getId());
            List<DictDetailDto> listres = dictDetailService.getDictByDictId(list2.get(0).getId());
            if (listres != null && listres.size() > 0) {
                for (DictDetailDto dictDetailDto : listres) {
                    Condition2 condition2 = new Condition2();
                    condition2.setType(2);//服务能力
                    condition2.setName(dictDetailDto.getLabel());
                    condition2.setCode(dictDetailDto.getValue());
                    condition2.setSort(dictDetailDto.getDictSort());

                    //判断此次字段发送是新增  还是编辑  还是删除
                    TechnologyReType byTypeLabel = technologyReTypeRepository.findByTypeLabel(2, dictDetailDto.getLabel());
                    if (byTypeLabel == null) {
                        //表示新增
                        condition2.setSync_status(1);
                        TechnologyReType technologyReType = new TechnologyReType();
                        technologyReType.setType(2);
                        technologyReType.setLabel(dictDetailDto.getLabel());
                        technologyReType.setValue(dictDetailDto.getValue());
                        technologyReType.setDictSort(dictDetailDto.getDictSort());
                        technologyReType.setIsdelete(dictDetailDto.getIsdelete());
                        technologyReTypeRepository.save(technologyReType);
                    } else {
                        //表示编辑
                        condition2.setSync_status(2);
                        byTypeLabel.setType(2);
                        byTypeLabel.setLabel(dictDetailDto.getLabel());
                        byTypeLabel.setValue(dictDetailDto.getValue());
                        byTypeLabel.setDictSort(dictDetailDto.getDictSort());
                        byTypeLabel.setIsdelete(dictDetailDto.getIsdelete());
                        technologyReTypeRepository.save(byTypeLabel);
                    }
                    list4.add(condition2);
                }

                if (dictByDictIdWithDelete2.size() > listres.size()) {
                    //说明有假删除
                    for (DictDetailDto dto : dictByDictIdWithDelete2) {
                        if (dto.getIsdelete() == 1) {
                            TechnologyReType byTypeLabel = technologyReTypeRepository.findByTypeLabel(2, dto.getLabel());
                            if (byTypeLabel != null) {
                                Integer isdelete = byTypeLabel.getIsdelete();
                                if (isdelete == 0) {
                                    //说明找到了设置为 删除状态
                                    //说明为刚删除  则需发送
                                    byTypeLabel.setIsdelete(1);
                                    byTypeLabel.setValue(dto.getValue());
                                    byTypeLabel.setDictSort(dto.getDictSort());
                                    technologyReTypeRepository.save(byTypeLabel);

                                    Condition2 condition2 = new Condition2();
                                    condition2.setType(2);//服务能力
                                    condition2.setName(dto.getLabel());
                                    condition2.setCode(dto.getValue());
                                    condition2.setSort(dto.getDictSort());
                                    condition2.setSync_status(3);
                                    list4.add(condition2);
                                }
                            }
                        }
                    }
                }
            }
        }


        if (list4 != null && list4.size() > 0) {
            for (Condition2 condition2 : list4) {
                DjDto2Single dto = new DjDto2Single();
                dto.setPath("/api.php?op=get_mst_fwjgsl");
                dto.setCondition(condition2);
                dto.setSystemCode("gyy");

                Gson gson = new Gson();
                String jsonString = gson.toJson(dto);
                sendApiReq(jsonString);
            }
        }
        return "success";
    }

    //劳模根据企业表，同名绑定其id至劳模表
    public void bindZqxQyId() {
        Boolean flag = true;
        if (flag) {
            List<SciPersonnelInfo> list = sciPersonnelInfoRepository.findNoDelete();
            if (list != null && list.size() > 0) {
                for (SciPersonnelInfo sciPersonnelInfo : list) {
                    String employer = sciPersonnelInfo.getEmployer();
                    List<SciEnterprise> list2 = sciEnterpriseRepository.queryPassEntertpriseByName("审核通过", "%" + employer + "%");
                    if (list2 != null && list2.size() == 1) {
                        SciEnterprise sciEnterprise = list2.get(0);
                        if (sciEnterprise != null) {
                            sciPersonnelInfo.setQyId(sciEnterprise.getId());
                            sciPersonnelInfoRepository.save(sciPersonnelInfo);
                        }
                    }
                }
            }
        } else {
            throw new BadRequestException("未执行该方法");
        }
    }
}